passenger

package
v0.0.0-...-5805fc1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2015 License: Apache-2.0 Imports: 22 Imported by: 0

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

View Source
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.

View Source
var ErrNoAuthHeader = errors.New("passenger: no authorization header present")

ErrNoAuthHeader signals that the request did not carry an Authorization header.

View Source
var ErrTokenExpired = errors.New("passenger: token expired")

ErrTokenExpired is returned if the token is not valid anymore.

View Source
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.

View Source
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

func NewContext(ctx context.Context, p *Passenger) context.Context

NewContext returns a new Context that carries value p.

func NewContextFromRequest

func NewContextFromRequest(ctx context.Context, r *http.Request) (context.Context, error)

NewContextFromRequest wraps FromRequest and NewContext.

Types

type ErrTokenNotMatchingUser

type ErrTokenNotMatchingUser struct {
	Parent, Actual *datastore.Key
}

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

type Passenger struct {
	User  *datastore.Key
	Token *model.Token
}

Passenger holds the currently authenticated user together with the token (if relevant).

func FromBasicAuth

func FromBasicAuth(ctx context.Context, username, pw string) (p *Passenger, err error)

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

func FromContext(ctx context.Context) (p *Passenger, ok bool)

FromContext returns the Passenger value stored in ctx if any.

func FromRequest

func FromRequest(ctx context.Context, r *http.Request) (*Passenger, error)

FromRequest inspects the HTTP Authorization header of the given request and tries to identify a passenger.

func FromToken

func FromToken(ctx context.Context, Token string) (*Passenger, error)

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

func (p *Passenger) HasScope(scope string) (has bool)

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

func (p *Passenger) IssueToken(ctx context.Context, token *model.Token) (string, error)

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.

func (*Passenger) Save

func (p *Passenger) Save(ctx context.Context) (*datastore.Key, error)

Save will persist the passenger to Datastore and send it to Memcache.

Jump to

Keyboard shortcuts

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