Documentation ¶
Index ¶
- Variables
- func Authenticator(next http.Handler) http.Handler
- func EpochNow() int64
- func ExpireIn(tm time.Duration) int64
- type Claims
- type JwtAuth
- func (ja *JwtAuth) Decode(tokenString string) (t *jwt.Token, err error)
- func (ja *JwtAuth) Encode(claims Claims) (t *jwt.Token, tokenString string, err error)
- func (ja *JwtAuth) IsExpired(t *jwt.Token) bool
- func (ja *JwtAuth) SetContext(ctx context.Context, t *jwt.Token, err error) context.Context
- func (ja *JwtAuth) Verifier(next http.Handler) http.Handler
- func (ja *JwtAuth) Verify(paramAliases ...string) func(http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
var ( ErrExpired = errors.New("jwtauth: expired token") )
Functions ¶
func Authenticator ¶
Authenticator is a default authentication middleware to enforce access following the Verifier middleware. The Authenticator sends a 401 Unauthorized response for all unverified tokens and passes the good ones through. It's just fine until you decide to write something similar and customize your client response.
Types ¶
type Claims ¶
type Claims map[string]interface{}
Claims is a convenience type to manage a JWT claims hash.
func (Claims) SetExpiryIn ¶
Set expiry ("exp") in the claims to some duration from the present time and return itself so it can be chained
func (Claims) SetIssuedAt ¶
Set issued at ("iat") to specified time in the claims
func (Claims) SetIssuedNow ¶
Set issued at ("iat") to present time in the claims
type JwtAuth ¶
type JwtAuth struct {
// contains filtered or unexported fields
}
func New ¶
New creates a JwtAuth authenticator instance that provides middleware handlers and encoding/decoding functions for JWT signing.
func NewWithParser ¶
NewWithParser is the same as New, except it supports custom parser settings introduced in ver. 2.4.0 of jwt-go
func (*JwtAuth) SetContext ¶
func (*JwtAuth) Verifier ¶
Verifier middleware will verify a JWT passed by a client request. The Verifier will look for a JWT token from: 1. 'jwt' URI query parameter 2. 'Authorization: BEARER T' request header 3. Cookie 'jwt' value
The verification processes finishes here and sets the token and a error in the request context and calls the next handler.
Make sure to have your own handler following the Validator that will check the value of the "jwt" and "jwt.err" in the context and respond to the client accordingly. A generic Authenticator middleware is provided by this package, that will return a 401 message for all unverified tokens, see jwtauth.Authenticator.