auth

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 14 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SessionRepository

type SessionRepository interface {
	Create(ctx context.Context, session *models.OAuthSession) error
	GetBySessionID(ctx context.Context, sessionID string) (*models.OAuthSession, error)
	UpdateRefreshToken(ctx context.Context, sessionID string, encryptedToken []byte, expiresAt time.Time) error
	DeleteBySessionID(ctx context.Context, sessionID string) error
	DeleteExpired(ctx context.Context, olderThan time.Duration) (int64, error)
}

SessionRepository defines the interface for OAuth session storage

type SessionService added in v1.2.1

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

SessionService manages user sessions independently of authentication method This service is always required, regardless of whether OAuth or MagicLink is used

func NewSessionService added in v1.2.1

func NewSessionService(config SessionServiceConfig) *SessionService

NewSessionService creates a new session service

func (*SessionService) GetNewSession added in v1.2.1

func (s *SessionService) GetNewSession(r *http.Request) (*sessions.Session, error)

GetNewSession creates a new session

func (*SessionService) GetSession added in v1.2.1

func (s *SessionService) GetSession(r *http.Request) (*sessions.Session, error)

GetSession returns the raw session (useful for storing additional data like OAuth state)

func (*SessionService) GetUser added in v1.2.1

func (s *SessionService) GetUser(r *http.Request) (*models.User, error)

GetUser retrieves the authenticated user from the session

func (*SessionService) Logout added in v1.2.1

func (s *SessionService) Logout(w http.ResponseWriter, r *http.Request)

Logout clears the user session

func (*SessionService) SetUser added in v1.2.1

func (s *SessionService) SetUser(w http.ResponseWriter, r *http.Request, user *models.User) error

SetUser stores a user in the session (works for both OAuth and MagicLink)

func (*SessionService) StoreRefreshToken added in v1.2.1

func (s *SessionService) StoreRefreshToken(ctx context.Context, w http.ResponseWriter, r *http.Request, token *oauth2.Token, user *models.User) error

StoreRefreshToken encrypts and stores the OAuth refresh token This is called by OAuthProvider after successful authentication

type SessionServiceConfig added in v1.2.1

type SessionServiceConfig struct {
	CookieSecret  []byte
	SecureCookies bool
	SessionRepo   SessionRepository
}

SessionServiceConfig holds configuration for the session service

type SessionWorker

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

SessionWorker handles background cleanup of expired OAuth sessions

func NewSessionWorker

func NewSessionWorker(sessionRepo SessionRepository, config SessionWorkerConfig, parentCtx context.Context, db *sql.DB, tenants tenant.Provider) *SessionWorker

NewSessionWorker creates a new OAuth session cleanup worker

func (*SessionWorker) Start

func (w *SessionWorker) Start() error

Start begins the cleanup worker

func (*SessionWorker) Stop

func (w *SessionWorker) Stop() error

Stop gracefully stops the worker

type SessionWorkerConfig

type SessionWorkerConfig struct {
	CleanupInterval time.Duration // How often to run cleanup (default: 24 hours)
	CleanupAge      time.Duration // Age of sessions to delete (default: 37 days = 30 + 7 grace period)
}

SessionWorkerConfig contains configuration for the session worker

func DefaultSessionWorkerConfig

func DefaultSessionWorkerConfig() SessionWorkerConfig

DefaultSessionWorkerConfig returns default session worker configuration

Jump to

Keyboard shortcuts

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