session

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 15 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

View Source
const (
	TypeAccessToken  = "access_token"
	TypeRefreshToken = "refresh_token"
)

Defines token types.

View Source
const SessionProtocolVersion = libsf.ProtocolVersion4

SessionProtocolVersion is the account version starting the support of sessions.

Variables

This section is empty.

Functions

func SecureCompare

func SecureCompare(s1, s2 string) bool

SecureCompare compares the givens strings in a constant time. So length info is not leaked via timing attacks.

func SecureToken

func SecureToken(length int) string

SecureToken generates a unique random token. Length should be 24 to match ActiveRecord::SecureToken used by the reference implementation.

func UserSupportsJWT

func UserSupportsJWT(user *model.User) bool

UserSupportsJWT returns true if the user supports the JWT authentication model.

func UserSupportsSessions

func UserSupportsSessions(user *model.User) bool

UserSupportsSessions returns true if the user supports the sessions authentication model.

Types

type Manager

type Manager interface {
	JWTSigningKey() []byte
	SessionSecret() []byte
	// Token generates the session's token for the given type t.
	Token(session *model.Session, t string) (string, error)
	// ParseToken parses the given raw token and returns the session_id and token.
	ParseToken(token string) (string, string, error)
	// Generate creates a new session without user information.
	Generate() *model.Session
	// Validate validates an access token.
	Validate(userID, token string) (*model.Session, error)
	// AccessTokenExprireAt returns the expiration date of the access token.
	AccessTokenExprireAt(session *model.Session) time.Time
	// Regenerate regenerates the session's tokens.
	Regenerate(session *model.Session) error
	// UserFromToken the user for the given token.
	UserFromToken(token any) (*model.User, error)
}

A Manager manages sessions.

func NewManager

func NewManager(db database.Client, signingKey, sessionSecret []byte, accessTokenExpirationTime, refreshTokenExpirationTime time.Duration) Manager

NewManager returns a new manager.

Jump to

Keyboard shortcuts

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