Documentation ¶
Overview ¶
Package passenger revolves around the User associated with the request in flight.
It establishes this link via the HTTP authorization header, which can be used to authenticate with basic authorization or token based authorization.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDigestMismatch = errors.New("passenger: digest mismatch")
ErrDigestMismatch is returned if the token provided by the user did not result in the same digest value after hashing as the one stored on the server.
var ErrNoAuthHeader = errors.New("passenger: no authorization header present")
ErrNoAuthHeader signals that the request did not carry an Authorization header.
var ErrTokenExpired = errors.New("passenger: token expired")
ErrTokenExpired is returned if the token is not valid anymore.
var ErrTokenNotAssociated = errors.New("passenger: token not associated to any user")
ErrTokenNotAssociated can be returned if this package encounters invalid data during authentication. A Token must be child of a User.
var ErrUnkAuthHeader = errors.New("passenger: cannot interpret authorization header")
ErrUnkAuthHeader is returned if the request contained an Authorization header, but it could not be parsed. The two accepted authorization methods are "Basic" and "Token".
Functions ¶
func NewContext ¶
NewContext returns a new Context that carries value p.
Types ¶
type ErrTokenNotMatchingUser ¶
ErrTokenNotMatchingUser is returned if basic auth with token password was attempted, and the token could be found but does not match the user.
func (ErrTokenNotMatchingUser) Error ¶
func (e ErrTokenNotMatchingUser) Error() string
type Passenger ¶
Passenger holds the currently authenticated user together with the token (if relevant).
func FromBasicAuth ¶
FromBasicAuth tries do identify a Passenger by the token he gave us. It will look up the the user by username and try to match password.
func FromContext ¶
FromContext returns the Passenger value stored in ctx if any.
func FromRequest ¶
FromRequest inspects the HTTP Authorization header of the given request and tries to identify a passenger.
func FromToken ¶
FromToken tries do identify a Passenger by the token he gave us. It will look up the Token and consequently the corresponding User.
func (*Passenger) HasScope ¶
HasScope can be used to check whether this Passenger was granted access to a given scope. Note that a user authenticated via username and password (not via token) will have access to all scopes by default.
func (*Passenger) IssueToken ¶
IssueToken creates a new Token for the authenticated user. Callers should prefill the Token with whatever values they like and leave zero values to be set. The generated token will also be persisted and can be handed to the client with no more handling.