Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrCodeInvalidAuthorizationHeader string ErrCodeInvalidTokenClaims string ErrCodeFailedToRefreshToken string )
var ( ErrNilAuthenticator = errors.New("authenticator cannot be nil") ErrInvalidAuthorizationHeader = errors.New("invalid authorization header") ErrNilOptions = errors.New("options cannot be nil") ErrNilRefreshTokenFn = errors.New("refresh token function cannot be nil") ErrNilCookieRefreshTokenName = errors.New("cookie refresh token name cannot be nil") ErrNilCookieAccessTokenName = errors.New("cookie access token name cannot be nil") )
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
AuthenticateFromHeader(
token gojwttoken.Token,
) func(next http.Handler) http.Handler
AuthenticateFromCookie(
token gojwttoken.Token,
) func(next http.Handler) http.Handler
}
Authenticator interface
type FailHandlerFn ¶ added in v0.10.0
type FailHandlerFn func( w http.ResponseWriter, err error, errorCode string, )
FailHandlerFn defines the function signature for handling authentication failures
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware struct is the authentication middleware
func NewMiddleware ¶
func NewMiddleware( responsesHandler gonethttphandler.ResponsesHandler, validator gojwtvalidator.Validator, options *Options, ) (*Middleware, error)
NewMiddleware creates a new authentication middleware
Parameters:
- responsesHandler: The HTTP handler to handle errors
- validator: The JWT validator service (if nil, no validation will be done, can be used for gRPC gateways)
- options: The options for the authentication middleware (can be nil)
Returns:
- *Middleware: The authentication middleware
func (Middleware) AuthenticateFromCookie ¶ added in v0.8.0
func (m Middleware) AuthenticateFromCookie( token gojwttoken.Token, ) func(next http.Handler) http.Handler
AuthenticateFromCookie return the middleware function that authenticates the request from the cookie
Parameters:
- token: The type of token to authenticate (access or refresh)
Returns:
- func(next http.Handler) http.Handler: The middleware function
func (Middleware) AuthenticateFromHeader ¶ added in v0.8.0
func (m Middleware) AuthenticateFromHeader( token gojwttoken.Token, ) func(next http.Handler) http.Handler
AuthenticateFromHeader return the middleware function that authenticates the request from the header
Parameters:
- token: The type of token to authenticate (access or refresh)
Returns:
- func(next http.Handler) http.Handler: The middleware function
type Options ¶ added in v0.11.1
type Options struct {
CookieRefreshTokenName *string
CookieAccessTokenName *string
RefreshTokenFn RefreshTokenFn
}
Options is the options for the authentication middleware
func NewOptions ¶ added in v0.11.1
func NewOptions( cookieRefreshTokenName, cookieAccessTokenName *string, refreshTokenFn RefreshTokenFn, ) *Options
NewOptions creates a new Options struct
Parameters:
- cookieRefreshTokenName: The name of the cookie that contains the refresh token
- cookieAccessTokenName: The name of the cookie that contains the access token
- refreshTokenFn: The function to refresh the access token using the refresh token
Returns:
- *Options: The options for the authentication middleware
type RefreshTokenFn ¶ added in v0.10.0
type RefreshTokenFn func( w http.ResponseWriter, r *http.Request, ) (map[gojwttoken.Token]string, error)
RefreshTokenFn defines the function signature for refreshing tokens