Documentation ¶
Index ¶
- Variables
- func Authenticator(next http.Handler) http.Handler
- func EpochNow() int64
- func ExpireIn(tm time.Duration) int64
- func StartAPI(hostname string, port string, DbConnectionInfo *configs.DbConnection)
- type Claims
- func (c Claims) Get(k string) (interface{}, bool)
- func (c Claims) Set(k string, v interface{}) Claims
- func (c Claims) SetExpiry(tm time.Time) Claims
- func (c Claims) SetExpiryIn(tm time.Duration) Claims
- func (c Claims) SetIssuedAt(tm time.Time) Claims
- func (c Claims) SetIssuedNow() Claims
- func (c Claims) Valid() error
- 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 ( errors.New("jwtauth: unauthorized token") // ErrExpired expired token error ErrExpired = errors.New("jwtauth: expired token") )ErrUnauthorized =
Functions ¶
func Authenticator ¶
Authenticator validate that user has a valid user auth token before letting him access.
func EpochNow ¶
func EpochNow() int64
EpochNow Helper function that returns the NumericDate time value used by the spec
Types ¶
type Claims ¶
type Claims map[string]interface{}
Claims is a convenience type to manage a JWT claims hash.
func (Claims) SetExpiry ¶
SetExpiry Set expiry ("exp") in the claims and return itself so it can be chained
func (Claims) SetExpiryIn ¶
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 ¶
SetIssuedAt Set issued at ("iat") to specified time in the claims
func (Claims) SetIssuedNow ¶
SetIssuedNow Set issued at ("iat") to present time in the claims
type JwtAuth ¶
type JwtAuth struct {
// contains filtered or unexported fields
}
JwtAuth struct to store JWT auth informations
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 ¶
SetContext set jwt && jwt.err in context
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.