Documentation
¶
Overview ¶
Package middleware implements various middlewares specific for long-season application usage.
Index ¶
- func ApiAuth(c models.Config, optional bool) func(next http.Handler) http.Handler
- func DeviceID(next http.Handler) http.Handler
- func JWT(ops *JWTOptions) func(http.Handler) http.Handler
- func Private(next http.Handler) http.Handler
- func RedirectLoggedIn(next http.Handler) http.Handler
- func URLParamInjection(param string) func(http.Handler) http.Handler
- func UpdateAuth(c *models.Config) func(http.Handler) http.Handler
- func UserID(next http.Handler) http.Handler
- type Extractor
- type JWTOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JWT ¶
func JWT(ops *JWTOptions) func(http.Handler) http.Handler
JWT checks if user has provided valid jwt token and then injects its content with jwt-user key into context.
func RedirectLoggedIn ¶
RedirectLoggedIn redirects logged in users to homepage. Make sure to inject JWT claims into request context first for proper working.
func URLParamInjection ¶
URLParamInjection injects given chi parameter into request context.
Types ¶
type Extractor ¶
Extractor is function for extracting JWT token in form of string. Error message should be readable for users and do not contains sensitive data.
type JWTOptions ¶
type JWTOptions struct { // Optional is flag, that will enable ignoring failed attempts // to login. Optional bool // Secret is jwt secret. The longer secret is, the better. Secret []byte // Algorithm is JWT algorithm used for signing Algorithm jwt.Algorithm // message. Unauthorized func(msg string, w http.ResponseWriter, r *http.Request) // InternalServerError handles cases when server fails during authorization. InternalServerError http.HandlerFunc // Functions for extracting JWT token in form of string. Extractors []Extractor // ContextKey will be set to JWT claims at request Context // after successful authorization. ContextKey string }
JWTOptions contains different fields intended for creating new JWT middleware.
Click to show internal directories.
Click to hide internal directories.