Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Manager
- func (m *Manager) Load(r *http.Request, v interface{}) error
- func (m *Manager) LoadBearer(r *http.Request, v interface{}) error
- func (m *Manager) LoadCookie(r *http.Request, v interface{}) error
- func (m *Manager) LoadHeadless(r *http.Request, v interface{}) error
- func (m *Manager) NewBearerToken(r *http.Request, k string, v interface{}) (string, error)
- func (m *Manager) NewCookieSession(r *http.Request, w http.ResponseWriter, v interface{}) error
- func (m *Manager) NewHeadlessToken(r *http.Request, k string, v interface{}) (string, error)
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 (*Manager) LoadBearer ¶ added in v0.19.0
LoadBearer loads a stateful session using the session from key the authorization header.
func (*Manager) LoadCookie ¶ added in v0.19.0
LoadCookie loads a stateful session from the request's cookie.
func (*Manager) LoadHeadless ¶ added in v0.19.0
LoadHeadless loads a stateless session from the encoded token in the authorization header.
func (*Manager) NewBearerToken ¶ added in v0.19.0
NewBearerToken creates a new token for bearer session access
func (*Manager) NewCookieSession ¶ added in v0.19.0
NewCookieSession creates and writes a cookie that gives access to the session
Click to show internal directories.
Click to hide internal directories.