session

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 15 Imported by: 0

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