middleware

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 7 Imported by: 0

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

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

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

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

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

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

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

Update calls f(user)

type UserUpdater

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