middleware

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 7 Imported by: 4

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

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 added in v0.12.0

func (a *Authenticator) RBAC(roles ...string) func(http.Handler) http.Handler

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 added in v0.11.0

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 added in v1.16.0

type BasicAuthFunc func(user, passwd string) (ok bool, userInfo token.User, err error)

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 added in v0.4.0

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 added in v0.11.0

type UserUpdFunc func(user token.User) token.User

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.

func (UserUpdFunc) Update added in v0.11.0

func (f UserUpdFunc) Update(user token.User) token.User

Update calls f(user)

type UserUpdater added in v0.11.0

type UserUpdater interface {
	Update(claims token.User) token.User
}

UserUpdater defines interface adding extras or modifying UserInfo in request context

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL