session

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated     = errors.New("unauthenticated")
	ErrSessionExpired      = errors.New("session expired")
	ErrSessionRevoked      = errors.New("session revoked")
	ErrInvalidSession      = errors.New("invalid session")
	ErrInvalidRefreshToken = errors.New("invalid refresh token")
	ErrRefreshTokenReuse   = errors.New("refresh token reuse")
	ErrForbidden           = errors.New("forbidden")
	ErrUserDisabled        = errors.New("user is disabled")
	ErrUserNotAllowed      = errors.New("user is not allowed")
)

Functions

func ClearSessionCookies

func ClearSessionCookies(w http.ResponseWriter)

func Configure

func Configure(secure bool)

func ReadAccessToken

func ReadAccessToken(r *http.Request) (string, bool)

func ReadRefreshToken

func ReadRefreshToken(r *http.Request) (string, bool)

func SetAccessToken

func SetAccessToken(w http.ResponseWriter, token string, maxAgeSeconds int)

func SetRefreshToken

func SetRefreshToken(w http.ResponseWriter, token string, maxAgeSeconds int)

Types

type AccessIdentity

type AccessIdentity struct {
	UserID    uuid.UUID
	SessionID uuid.UUID
	Roles     roles.Roles
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(cfg SessionConfig) *Service

func (*Service) CleanupExpiredData added in v0.1.6

func (s *Service) CleanupExpiredData(ctx context.Context, now time.Time) error

func (*Service) CreateSession

func (s *Service) CreateSession(
	ctx context.Context,
	userID uuid.UUID,
	audience token.Audience,
	userAgent string,
	now time.Time,
) (
	accessToken string,
	refreshToken string,
	err error,
)

func (*Service) ListUserSessions added in v0.1.16

func (s *Service) ListUserSessions(
	ctx context.Context,
	userID uuid.UUID,
	currentSessionID uuid.UUID,
	now time.Time,
) ([]domain.Session, error)

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, refreshToken string) error

func (*Service) RefreshSession

func (s *Service) RefreshSession(ctx context.Context, refreshToken string, audience token.Audience, now time.Time) (newAccessToken string, newRefreshToken string, err error)

func (*Service) RevokeAllSessions

func (s *Service) RevokeAllSessions(ctx context.Context, userID uuid.UUID) error

func (*Service) RevokeOtherUserSessions added in v0.1.16

func (s *Service) RevokeOtherUserSessions(
	ctx context.Context,
	userID uuid.UUID,
	currentSessionID uuid.UUID,
	now time.Time,
) error

func (*Service) RevokeUserSession added in v0.1.16

func (s *Service) RevokeUserSession(
	ctx context.Context,
	userID uuid.UUID,
	sessionID uuid.UUID,
	now time.Time,
) error

func (*Service) StartCleanupWorker added in v0.1.6

func (s *Service) StartCleanupWorker(ctx context.Context, logger *slog.Logger, interval time.Duration)

func (*Service) ValidateAccessToken

func (s *Service) ValidateAccessToken(
	accessToken string,
	expectedAudience token.Audience,
	now time.Time,
) (*AccessIdentity, error)

func (*Service) ValidateAnyAccessToken added in v0.1.13

func (s *Service) ValidateAnyAccessToken(
	accessToken string,
	now time.Time,
) (*AccessIdentity, error)

type SessionConfig

type SessionConfig struct {
	Store                *store.Store
	Tx                   *tx.Manager
	AccessTokens         *token.AccessTokenService
	SessionTTL           time.Duration
	RefreshTokenTTL      time.Duration
	RefreshTokenRotation time.Duration
	AccessPolicy         accesspolicy.EmailAccessPolicy
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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