sessions

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSessionKey      = "anansi_session"
	DefaultHeadlessScheme  = "API"
	DefaultSessionDuration = time.Hour
)

Variables

View Source
var (
	// ErrHeaderFormat is returned when the authorization header doesn't
	// contain 2 fields separated by whitespace.
	ErrHeaderFormat = errors.New("incorrect authorization header format")
	// ErrEmptyHeader is returned when the authorization header is not set
	ErrEmptyHeader = errors.New("empty authorization header")
	// ErrUnsupportedScheme is returned when the scheme is either not bearer nor the set custom scheme
	ErrUnsupportedScheme = errors.New("unsupported authorization scheme")
	// ErrEmptyAuthCookie is returned when the authentication cookie is not set
	ErrEmptyAuthCookie = errors.New("no cookie set for session")
)

Functions

This section is empty.

Types

type Config added in v0.19.0

type Config struct {
	// Signals whether the app is running in a production environment
	IsProduction bool
	// The scheme to recognise for headless requests. defaults to
	// DefaultHeadlessScheme
	HeadlessScheme string
	// How long each headless session should last Config.BearerDuration
	HeadlessDuration time.Duration
	// How long bearer sessions should last. Defaults to DefaultSessionDuration
	BearerDuration time.Duration
	// The name of the server cookie the session token is written to
	CookieKey string
	// How long cookie sessions should last. Defaults to Config.BearerDuration
	CookieDuration time.Duration
}

Config defines particular controls for session management

type Manager added in v0.19.0

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

func NewManager added in v0.19.0

func NewManager(store tokens.Store, secret []byte, config Config) *Manager

func (*Manager) Load added in v0.19.0

func (m *Manager) Load(r *http.Request, v interface{}) error

Load to load either bearer, cookie or headless session

func (*Manager) LoadBearer added in v0.19.0

func (m *Manager) LoadBearer(r *http.Request, v interface{}) error

LoadBearer loads a stateful session using the session from key the authorization header.

func (*Manager) LoadCookie added in v0.19.0

func (m *Manager) LoadCookie(r *http.Request, v interface{}) error

LoadCookie loads a stateful session from the request's cookie.

func (*Manager) LoadHeadless added in v0.19.0

func (m *Manager) LoadHeadless(r *http.Request, v interface{}) error

LoadHeadless loads a stateless session from the encoded token in the authorization header.

func (*Manager) NewBearerToken added in v0.19.0

func (m *Manager) NewBearerToken(r *http.Request, k string, v interface{}) (string, error)

NewBearerToken creates a new token for bearer session access

func (*Manager) NewCookieSession added in v0.19.0

func (m *Manager) NewCookieSession(r *http.Request, w http.ResponseWriter, v interface{}) error

NewCookieSession creates and writes a cookie that gives access to the session

func (*Manager) NewHeadlessToken added in v0.19.0

func (m *Manager) NewHeadlessToken(r *http.Request, k string, v interface{}) (string, error)

NewHeadlessToken creates a new token for headless session access

Jump to

Keyboard shortcuts

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