Documentation ¶
Overview ¶
Package jwt implements a simple, opinionated net/http-compatible middleware for integrating JSON Web Tokens (JWT).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrMissingConfig = errors.New("missing configuration") ErrMissingSecret = errors.New("please provide a shared secret") ErrMissingAuthFunc = errors.New("please provide an auth function") ErrMissingClaimsFunc = errors.New("please provide a claims function") ErrEncoding = errors.New("error encoding value") ErrDecoding = errors.New("error decoding value") ErrMissingToken = errors.New("please provide a token") ErrMalformedToken = errors.New("please provide a valid token") ErrInvalidSignature = errors.New("signature could not be verified") ErrParsingCredentials = errors.New("error parsing credentials") ErrInvalidMethod = errors.New("invalid request method") )
Errors introduced by this package.
Functions ¶
This section is empty.
Types ¶
type ClaimsFunc ¶
ClaimsFunc is a type for delegating claims generation to the client-code.
type Config ¶
type Config struct { Secret string Auth AuthFunc Claims ClaimsFunc IdentityField string VerifyField string }
Config is a container for setting up the JWT middleware.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is where we store all the specifics related to the client's JWT needs.
func New ¶
func New(c *Config) (*Middleware, error)
New creates a new Middleware from a user-specified configuration.
func (*Middleware) Authenticate ¶
func (m *Middleware) Authenticate() http.Handler
Authenticate returns a middleware that parsing an incoming request for a JWT, calls the client-supplied auth function, and if successful, returns a JWT to the requester.
func (*Middleware) CreateToken ¶
func (m *Middleware) CreateToken(identity string) (string, error)
CreateToken generates a token from a user's identity
func (*Middleware) Secure ¶
func (m *Middleware) Secure(h http.Handler, v VerifyClaimsFunc) http.Handler
Secure wraps a client-specified http.Handler with a verification function, as well as-built in parsing of the request's JWT. This allows each handler to have it's own verification/validation protocol.
func (*Middleware) VerifyToken ¶
func (m *Middleware) VerifyToken(token string, v VerifyClaimsFunc, r *http.Request) (int, string, error)
VerifyToken verifies a token