auth

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 15 Imported by: 0

Documentation

Overview

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 Config

type Config struct {
	BaseURL       string
	ClientID      string
	ClientSecret  string
	AuthURL       string
	TokenURL      string
	UserInfoURL   string
	LogoutURL     string
	Scopes        []string
	AllowedDomain string
	CookieSecret  []byte
	SecureCookies bool
	SessionRepo   SessionRepository
}

type OauthService

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

func NewOAuthService

func NewOAuthService(config Config) *OauthService

func (*OauthService) CreateAuthURL

func (s *OauthService) CreateAuthURL(w http.ResponseWriter, r *http.Request, nextURL string) string

func (*OauthService) GetAuthURL

func (s *OauthService) GetAuthURL(nextURL string) string

func (*OauthService) GetLogoutURL

func (s *OauthService) GetLogoutURL() string

GetLogoutURL returns the SSO logout URL if configured, otherwise returns empty string

func (*OauthService) GetUser

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

func (*OauthService) HandleCallback

func (s *OauthService) HandleCallback(ctx context.Context, w http.ResponseWriter, r *http.Request, code, state string) (*models.User, string, error)

func (*OauthService) IsAllowedDomain

func (s *OauthService) IsAllowedDomain(email string) bool

func (*OauthService) Logout

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

func (*OauthService) SetUser

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

func (*OauthService) VerifyState

func (s *OauthService) VerifyState(w http.ResponseWriter, r *http.Request, stateToken string) bool

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 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) *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