Documentation ¶
Overview ¶
Package jwt provides a easy to use JSON Web Token and blacklisting library
Index ¶
Constants ¶
const ( HS256Name = "HS256" HS384Name = "HS384" HS512Name = "HS512" )
const ( // Header is the default HTTP Authorization header name Header = "Authorization" // DefaultExpiry is the default token expiration time DefaultExpiry = time.Hour * 12 )
Variables ¶
var ( ErrNoJWT = errors.New("no json web token") ErrUnsupportedAlg = errors.New("unsupported algorithm") ErrInvalid = errors.New("token validation failed") ErrBlacklisted = errors.New("token blacklisted") ErrBlacklistNotEnabled = errors.New("blacklisting is not enabled") ErrNBF = errors.New("token not valid yet") ErrEXP = errors.New("token expired") ErrMissingEXP = errors.New("missing exp claim") ErrMissingTokenParts = errors.New("missíng token parts") ErrEmptySignature = errors.New("token signature is empty") ErrTokenIsNil = errors.New("token is nil") )
Functions ¶
This section is empty.
Types ¶
type JWT ¶
JWT represents the JSON Web Token signing and blacklisting infrastructure
func New ¶
New returns a new JWT object with the given expiry timeout. If the timeout is less or equal to zero the default expiry (12 hours) is used. If blacklisting is enabled, the JWT object leaks a goroutine to garbage-collect expired blacklisted tokens. Call the Stop() method to exit the goroutine.
func (*JWT) Invalidate ¶
Invalidate checks if a token is already blacklisted If the token is not blacklisted, it will get blacklisted
func (*JWT) Sign ¶
Sign will sign the provided token using the secret key This will overwrite existing 'exp' and 'nbf' claims
type Token ¶
type Token struct { Claims map[string]interface{} // contains filtered or unexported fields }
Token is the JWT token representation
func DecodeToken ¶
DecodeToken decodes a raw string token into a *Token object
func NewToken ¶
NewToken returns a new *Token using the provided hash algorithm and claims If h is nil HS256 will be used