Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrObsoleteToken = errors.New("obsolete token format") ErrTokenFormat = errors.New("badly formatted token") ErrSalted = errors.New("token already salted") )
var DecodeTokenCookie func(string) ([]byte, error) = base64.URLEncoding.DecodeString
DecodeTokenCookie accepts a cookie value and returns the encoded token.
var EncodeTokenCookie func([]byte) string = base64.URLEncoding.EncodeToString
EncodeTokenCookie accepts a token and returns a byte slice suitable for use as a cookie value, such that it will be decoded correctly by LoadTokensFromHTTPRequest.
Functions ¶
func LoadToken ¶
LoadToken wraps the next handler, adding credentials to the request context so subsequent handlers can access them efficiently via CredentialsFromRequest.
func RequireLiteralToken ¶
RequireLiteralToken wraps the next handler, rejecting any request that doesn't supply the given token. If the given token is empty, RequireLiteralToken returns next (i.e., no auth checks are performed).
Types ¶
type Credentials ¶
type Credentials struct {
Tokens []string
}
func CredentialsFromRequest ¶
func CredentialsFromRequest(r *http.Request) *Credentials
func FromContext ¶
func FromContext(ctx context.Context) (*Credentials, bool)
func NewCredentials ¶
func NewCredentials(tokens ...string) *Credentials
func (*Credentials) LoadTokensFromHTTPRequest ¶
func (a *Credentials) LoadTokensFromHTTPRequest(r *http.Request)
LoadTokensFromHTTPRequest loads all tokens it can find in the headers and query string of an http query.
func (*Credentials) LoadTokensFromHTTPRequestBody ¶
func (a *Credentials) LoadTokensFromHTTPRequestBody(r *http.Request) error
LoadTokensFromHTTPRequestBody loads credentials from the request body.
This is separate from LoadTokensFromHTTPRequest() because it's not always desirable to read the request body. This has to be requested explicitly by the application.