Documentation
¶
Overview ¶
Package session contains types and functions for working with authentication sessions.
Index ¶
Constants ¶
const Leeway = time.Second * 5
Leeway is the amount of leeway permitted in a session's expiration time allowing for clock skew between the authenticator and the client.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClaimsDecoder ¶
A ClaimsDecoder is an interface for decoding JWT claims into a target JSON-decodable object.
type MissingRequiredClaimError ¶
type MissingRequiredClaimError struct {
Claim string
}
MissingRequiredClaimError is returned when a required claim is not provided.
func (MissingRequiredClaimError) Error ¶
func (e MissingRequiredClaimError) Error() string
type Session ¶
type Session struct {
Anonymous bool `json:"-"`
UID string `json:"u"`
ExpiresAt int64 `json:"e,omitempty"`
Claims json.RawMessage `json:"c,omitempty"`
}
Session represents an authentication session. A session can be one that is authenticated (anonymous) or authenticated with a user identity. A session may optionally expire.
func Anonymous ¶
func Anonymous() *Session
Anonymous returns a session to use when a request is unauthenticated.
func NewFromClaims ¶
func NewFromClaims(uidClaim string, claims ClaimsDecoder) (*Session, error)
NewFromClaims creates a new session from JWT claims. It assumes that the provided claims have been already validated.
The provided uidClaim is used to extract the username from the token's claims. It must exist and be a string type in the token's claims.