session

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) 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) 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(ctx context.Context, 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