auth

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2018 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// TokenKey is the request context key that points to the generated token.
	TokenKey contextKey = "token"

	// ClaimsKey is the request context key that points to any JWT claims in
	// the current request.
	ClaimsKey contextKey = "claims"
)

Variables

This section is empty.

Functions

func Claims

func Claims(r *http.Request) jwt.Claims

Claims returns the claims stored in the request

func RequireToken

func RequireToken(h http.Handler, validator TokenValidator, secret []byte, opts ...TokenOpt) http.Handler

func Token

func Token(r *http.Request) string

Token returns the token string stored in the request context, or an empty string.

func TokenBlacklister

func TokenBlacklister(h http.Handler, store TokenStorage, secret []byte, opts ...TokenOpt) http.Handler

TokenBlacklister returns a handler that will blacklist any token found in the request. Typically to be used around logout handlers.

If handler h is nil, upon successful blacklist, 200 OK is returned.

func TokenGenerator

func TokenGenerator(h http.Handler, auth Authenticator, secret []byte, opts ...TokenOpt) http.Handler

TokenGenerator returns a handler that will read a username and password from a request form, create a jwt token if they are valid, and store the signed token in the request context for later consumption.

If handler h is nil, the generated token will be written verbatim in the response.

Types

type Authenticator

type Authenticator interface {
	// Authenticate returns true if the supplied username and password are valid
	Authenticate(user, password string) bool
}

Authenticator is responsible for specifying whether a user-password tuple is valid.

type AuthenticatorFunc

type AuthenticatorFunc func(user, password string) bool

The AuthenticatorFunc type is an adapter to allow using ordinary functions as authenticators.

func (AuthenticatorFunc) Authenticate

func (a AuthenticatorFunc) Authenticate(user, password string) bool

type TokenOpt

type TokenOpt struct {
	// contains filtered or unexported fields
}

A TokenOpt is used to change the default behaviour of token handlers.

func Claimer

func Claimer(c func(claims *jwt.StandardClaims) jwt.Claims) TokenOpt

Claimer is responsible for transforming a standard claims object into a custom one.

func Expiration

func Expiration(e time.Duration) TokenOpt

Expiration sets the expiration time of the auth token

func Extractor

func Extractor(e request.Extractor) TokenOpt

Extractor extracts a token from a request

func Issuer

func Issuer(issuer string) TokenOpt

Issuer sets the issuer in the standart claims object.

func Logger

func Logger(l handler.Logger) TokenOpt

Logger defines the logger to be used whenever detailed messages have to be printed out.

func Password

func Password(password string) TokenOpt

Password sets the query key from which to obtain the password.

func User

func User(user string) TokenOpt

User sets the query key from which to obtain the user.

type TokenStorage

type TokenStorage interface {
	Store(token string, expiration time.Time) error
}

TokenStorage stores the given token string along with its expiration time.

type TokenStorageFunc

type TokenStorageFunc func(token string, expiration time.Time) error

The TokenStorageFunc type is an adapter to allow using ordinary functions as token storage.

func (TokenStorageFunc) Store

func (t TokenStorageFunc) Store(token string, expiration time.Time) error

type TokenValidator

type TokenValidator interface {
	Validate(token string, claims jwt.Claims) bool
}

TokenValidator checks if the given token is valid.

type TokenValidatorFunc

type TokenValidatorFunc func(token string, claims jwt.Claims) bool

The TokenValidatorFunc type is an adapter to allow using ordinary functions as token storage.

func (TokenValidatorFunc) Validate

func (t TokenValidatorFunc) Validate(token string, claims jwt.Claims) bool

Jump to

Keyboard shortcuts

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