Documentation ¶
Index ¶
Constants ¶
const ( //ErrorTokenIsEmpty means that middleware could not find Bearer JWT token in headers ErrorTokenIsEmpty = "middleware.token_is_empty" //ErrorTokenIsInvalid token validation failed ErrorTokenIsInvalid = "middleware.token_is_invalid" )
const ( // AuthorizationHeaderKey is a header name for Bearer token. AuthorizationHeaderKey = "Authorization" // TokenTypeAccess is an access token type. TokenTypeAccess = "access" // TokenTypeRefresh is a refresh token type. TokenTypeRefresh = "refresh" // AccessTokenContextKey context key to store and retreive access token AccessTokenContextKey = "identifo.token.access" // RefreshTokenContextKey context key to store and retreive refresh token RefreshTokenContextKey = "identifo.token.refresh" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error string
Error represents error for middleware
func (Error) Description ¶
Description returns description for error
type ErrorHandler ¶
type ErrorHandler interface {
Error(rw http.ResponseWriter, errorType Error, status int, description string)
}
ErrorHandler interface for handling error from middleware rw - http.ResponseWriter to write error to (JSON, HTML or other error to the client) errorType - error returned from middleware, you can get description by calling errorType.Description() status - http status code
type Handler ¶
type Handler func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Handler is a full copy of negroni.HandlerFunc this is the same http.HandlerFunc, it just has one additional parameter 'next' next is a reference to the next handler in the handler chain
func JWT ¶
func JWT(eh ErrorHandler, c validator.Config) (Handler, error)
JWT returns middleware function you can use to handle JWT token auth Deprecated: use JWT instead
func JWTv2 ¶ added in v2.11.0
func JWTv2(eh JWTErrorHandler, c validator.Config) (Handler, error)
JWTv2 returns middleware function you can use to handle JWT token auth. It extracts token from Authorization header, validates it and stores the parsed token in the context, use TokenFromContext to get token from context. It uses JWTErrorHandler to handle errors.
type JWTErrorHandler ¶ added in v2.11.0
type JWTErrorHandler interface {
Error(errContext *JWTErrorHandlerContext)
}
JWTErrorHandler is an interface for handling errors from JWTv2 middleware.
type JWTErrorHandlerContext ¶ added in v2.11.0
type JWTErrorHandlerContext struct { // ResponseWriter is an http.ResponseWriter to write error to (JSON, HTML or other error to the client). ResponseWriter http.ResponseWriter // Request is an http.Request to get more information about the request. Request *http.Request // ErrorType is an error returned from middleware, you can get description by calling errorType.Description(). ErrorType Error // Status is an http status code. Status int // Description is a description of the error. Description string // Token is a parsed but not valid token, may be nil. Token model.Token }
JWTErrorHandlerContext is a context for handling errors from JWTv2 middleware.