session

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSession

func CreateSession(session Session) error

func DeactivateSessionByID added in v1.0.0

func DeactivateSessionByID(sessionID string) error

func HandleLogout

func HandleLogout(w http.ResponseWriter, r *http.Request)

HandleLogout godoc @Summary Log out a user @Description Terminates the user's session @Tags session @Accept json @Produce json @Param Authorization header string true "Bearer access token" @Success 200 {string} string "Session terminated successfully" @Failure 401 {object} model.ApiError @Failure 500 {object} model.ApiError @Router /oauth2/logout [post]

func HandleSessionAdminEndpoint added in v1.0.0

func HandleSessionAdminEndpoint(w http.ResponseWriter, r *http.Request)

HandleSessionAdminEndpoint is the combined handler for /admin/api/sessions @Summary Session administration @Description GET: List all active sessions or filter by user ID. DELETE: Deactivate a specific session. @Tags sessions-admin @Accept json @Produce json @Param user_id query string false "Filter sessions by User ID (GET)" @Param id query string false "Session ID to deactivate (DELETE)" @Security BearerAuth @Success 200 {array} SessionResponse "List of sessions (GET)" @Success 200 {object} map[string]string "Deactivation result (DELETE)" @Router /admin/api/sessions [get] @Router /admin/api/sessions [delete]

Types

type Session

type Session struct {
	ID             string
	UserID         string
	AccessToken    string
	RefreshToken   string
	UserAgent      string
	IPAddress      string
	DeviceID       *string
	LastActivityAt *time.Time
	CreatedAt      time.Time
	ExpiresAt      time.Time
	DeactivatedAt  *time.Time
	Location       string
}

func ListSessions added in v1.0.0

func ListSessions() ([]*Session, error)

func ListSessionsByUser added in v1.0.0

func ListSessionsByUser(userID string) ([]*Session, error)

func SessionByAccessToken

func SessionByAccessToken(accessToken string) (*Session, error)

func SessionByID

func SessionByID(sessionID string) (*Session, error)

func (*Session) ToResponse added in v1.0.0

func (s *Session) ToResponse() SessionResponse

type SessionResponse added in v1.0.0

type SessionResponse struct {
	ID             string     `json:"id"`
	UserID         string     `json:"user_id"`
	UserAgent      string     `json:"user_agent"`
	IPAddress      string     `json:"ip_address"`
	DeviceID       *string    `json:"device_id"`
	LastActivityAt *time.Time `json:"last_activity_at"`
	CreatedAt      time.Time  `json:"created_at"`
	ExpiresAt      time.Time  `json:"expires_at"`
	DeactivatedAt  *time.Time `json:"deactivated_at"`
	Location       string     `json:"location"`
	Status         string     `json:"status"`
}

SessionResponse is the admin-safe representation (no tokens)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL