Documentation ¶
Overview ¶
Package middleware provides login middlewares: - Auth: adds auth from session and populates user info - Trace: populates user info if token presented - AdminOnly: restrict access to admin users only
Index ¶
- type Authenticator
- func (a *Authenticator) AdminOnly(next http.Handler) http.Handler
- func (a *Authenticator) Auth(next http.Handler) http.Handler
- func (a *Authenticator) RBAC(roles ...string) func(http.Handler) http.Handler
- func (a *Authenticator) Trace(next http.Handler) http.Handler
- func (a *Authenticator) UpdateUser(upd UserUpdater) func(http.Handler) http.Handler
- type BasicAuthFunc
- type RefreshCache
- type TokenService
- type UserUpdFunc
- type UserUpdater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator struct { logger.L JWTService TokenService Providers []provider.Service Validator token.Validator AdminPasswd string BasicAuthChecker BasicAuthFunc RefreshCache RefreshCache }
Authenticator is top level auth object providing middlewares
func (*Authenticator) AdminOnly ¶
func (a *Authenticator) AdminOnly(next http.Handler) http.Handler
AdminOnly middleware allows access for admins only this handler internally wrapped with auth(true) to avoid situation if AdminOnly defined without prior Auth
func (*Authenticator) Auth ¶
func (a *Authenticator) Auth(next http.Handler) http.Handler
Auth middleware adds auth from session and populates user info
func (*Authenticator) RBAC ¶
RBAC middleware allows role based control for routes this handler internally wrapped with auth(true) to avoid situation if RBAC defined without prior Auth
func (*Authenticator) Trace ¶
func (a *Authenticator) Trace(next http.Handler) http.Handler
Trace middleware doesn't require valid user but if user info presented populates info
func (*Authenticator) UpdateUser ¶
func (a *Authenticator) UpdateUser(upd UserUpdater) func(http.Handler) http.Handler
UpdateUser update user info with UserUpdater if it exists in request's context. Otherwise do nothing. should be placed after either Auth, Trace. AdminOnly or RBAC middleware.
type BasicAuthFunc ¶
BasicAuthFunc type is an adapter to allow the use of ordinary functions as BasicAuth. The second return parameter `User` need for add user claims into context of request.
type RefreshCache ¶
type RefreshCache interface { Get(key interface{}) (value interface{}, ok bool) Set(key, value interface{}) }
RefreshCache defines interface storing and retrieving refreshed tokens
type TokenService ¶
type TokenService interface { Parse(tokenString string) (claims token.Claims, err error) Set(w http.ResponseWriter, claims token.Claims) (token.Claims, error) Get(r *http.Request) (claims token.Claims, token string, err error) IsExpired(claims token.Claims) bool Reset(w http.ResponseWriter) }
TokenService defines interface accessing tokens
type UserUpdFunc ¶
UserUpdFunc type is an adapter to allow the use of ordinary functions as UserUpdater. If f is a function with the appropriate signature, UserUpdFunc(f) is a Handler that calls f.