authentication

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const SignupDisabledError = "signup is currently disabled"
View Source
const TokenScopesMetadataKey = "x-token-scopes"

Variables

This section is empty.

Functions

func AccountSessionMaxAge added in v0.25.0

func AccountSessionMaxAge() time.Duration

AccountSessionMaxAge returns the absolute lifetime of a login session, measured from the first sign-in, regardless of sliding refresh. Override with ACCOUNT_SESSION_MAX_AGE.

func AccountSessionTTL added in v0.25.0

func AccountSessionTTL() time.Duration

AccountSessionTTL returns how long account_token cookies remain valid between activity refreshes. Override with ACCOUNT_SESSION_TTL.

func ClearAccountCookie

func ClearAccountCookie(w http.ResponseWriter, r *http.Request)

func GenerateAccountToken added in v0.25.0

func GenerateAccountToken(jwtSigner *jwt.Signer, accountID string, sessionStart time.Time, ttl time.Duration) (string, error)

GenerateAccountToken creates a signed account_token JWT with session tracking.

func GetOrganizationIdFromMetadata

func GetOrganizationIdFromMetadata(ctx context.Context) (string, bool)

func GetScopedTokenScopesFromMetadata added in v0.14.0

func GetScopedTokenScopesFromMetadata(ctx context.Context) ([]string, bool)

func GetUserIdFromMetadata

func GetUserIdFromMetadata(ctx context.Context) (string, bool)

func IsAccountSessionWithinMaxAge added in v0.25.0

func IsAccountSessionWithinMaxAge(claims jwtLib.MapClaims) bool

IsAccountSessionWithinMaxAge reports whether the session is still within its absolute lifetime cap. Tokens without ses are rejected.

func IssueAccountSession added in v0.25.0

func IssueAccountSession(w http.ResponseWriter, r *http.Request, jwtSigner *jwt.Signer, accountID string) error

IssueAccountSession mints a fresh account_token for a new login session.

func MaybeRefreshAccountSession added in v0.25.0

func MaybeRefreshAccountSession(w http.ResponseWriter, r *http.Request, jwtSigner *jwt.Signer, account *models.Account)

MaybeRefreshAccountSession extends active sessions using a sliding window. Any authenticated activity reissues the token for another full TTL, except when the token was just minted or the absolute session max age is reached.

func ResetAccountSessionTTLForTests added in v0.25.0

func ResetAccountSessionTTLForTests()

ResetAccountSessionTTLForTests clears cached session duration settings.

func SessionStartFromClaims added in v0.25.0

func SessionStartFromClaims(claims jwtLib.MapClaims) (time.Time, bool)

SessionStartFromClaims returns when the login session began from the ses claim. Tokens without ses cannot be used for absolute max-age enforcement.

func SetAccountCookie added in v0.21.0

func SetAccountCookie(w http.ResponseWriter, r *http.Request, token string, ttl time.Duration)

SetAccountCookie writes the account_token cookie with the same flags used by every login path. Centralized so callers (login, signup, magic code, change-password reissue) cannot drift on cookie attributes.

func SetUserIdInMetadata

func SetUserIdInMetadata(ctx context.Context, userId string) context.Context

Types

type Handler

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

func NewHandler

func NewHandler(jwtSigner *jwt.Signer, encryptor crypto.Encryptor, authService authorization.Authorization, appEnv string, templateDir string, blockSignup bool, passwordLoginEnabled bool, magicCodeEnabled bool) *Handler

func (*Handler) FindOrCreateAccountForProvider

func (a *Handler) FindOrCreateAccountForProvider(gothUser goth.User) (*models.Account, error)

func (*Handler) InitializeProviders

func (a *Handler) InitializeProviders(providers map[string]ProviderConfig)

func (*Handler) PasswordLoginEnabled added in v0.21.0

func (a *Handler) PasswordLoginEnabled() bool

PasswordLoginEnabled reports whether email/password authentication is currently enabled for this installation. Used by handlers outside this package (e.g. the change-password endpoint) that should refuse work when the feature is disabled.

func (*Handler) RegisterRoutes

func (a *Handler) RegisterRoutes(router *mux.Router)

type ProviderConfig

type ProviderConfig struct {
	Key         string
	Secret      string
	CallbackURL string
}

Jump to

Keyboard shortcuts

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