Documentation
¶
Index ¶
- func Claims(r *http.Request) jwt.Claims
- func RequireToken(h http.Handler, validator TokenValidator, secret []byte, opts ...TokenOpt) http.Handler
- func Token(r *http.Request) string
- func TokenBlacklister(h http.Handler, store TokenStorage, secret []byte, opts ...TokenOpt) http.Handler
- func TokenGenerator(h http.Handler, auth Authenticator, secret []byte, opts ...TokenOpt) http.Handler
- type Authenticator
- type AuthenticatorFunc
- type TokenOpt
- func Claimer(c func(claims *jwt.StandardClaims) jwt.Claims) TokenOpt
- func Expiration(e time.Duration) TokenOpt
- func Extractor(e request.Extractor) TokenOpt
- func Issuer(issuer string) TokenOpt
- func Logger(l handler.Logger) TokenOpt
- func Password(password string) TokenOpt
- func User(user string) TokenOpt
- type TokenStorage
- type TokenStorageFunc
- type TokenValidator
- type TokenValidatorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequireToken ¶
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 ¶
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 ¶
Expiration sets the expiration time of the auth token
func Logger ¶
Logger defines the logger to be used whenever detailed messages have to be printed out.
type TokenStorage ¶
TokenStorage stores the given token string along with its expiration time.
type TokenStorageFunc ¶
The TokenStorageFunc type is an adapter to allow using ordinary functions as token storage.
type TokenValidator ¶
TokenValidator checks if the given token is valid.