session

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 17 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
	OrganizationID   uuid.UUID
	OrganizationRole domain.OrganizationRole
	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, accessToken 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) RevokeAccessToken added in v0.13.0

func (s *Service) RevokeAccessToken(ctx context.Context, accessToken string, now time.Time) 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) SwitchSessionOrganization added in v0.1.24

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

func (*Service) ValidateAccessToken

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

func (*Service) ValidateAnyAccessToken added in v0.1.13

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

type SessionConfig

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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