authorization

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppHandler

type AppHandler func(w http.ResponseWriter, r *http.Request, userInfo *UserInfo) error

AppHandler is handler that will fail if user is not authorized (based on token + required scope)

func (AppHandler) ServeHTTP

func (ah AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Satisfies the http.Handler interface

type Authorization

type Authorization struct {
	// contains filtered or unexported fields
}

Authorization object

func New

func New(options Options) (a *Authorization)

New create new AuthMiddleware object

func (*Authorization) Middleware

func (a *Authorization) Middleware(h http.Handler) (handler http.Handler)

Middleware returns middleware function that can be used in router.Use()

func (*Authorization) Validate added in v0.3.0

func (a *Authorization) Validate() (err error)

type Options added in v0.3.0

type Options struct {
	// Jwks with private key. If not set, authorization will be disabled,
	Jwks jwk.Set
	// As alternative to Jwks, JwksURL can be provided. Middleware will fetch Jwks and auto refresh.
	// If Jwks is provided, JwksURL will be ignored.
	JwksURL string
	// Required scope that needs to be present in token. If given scope is not present
	// request will be denied. Scope '*' can be set and means any - only key must match.
	RequiredScope string
	// Allowes anonymous user - user without token. User info will be null
	AllowAnonymous bool
	// Way how to treat invalid user token: anonymous or unauthorized
	InvalidTokenIsAnonymous bool
	// Way how to treat users without valid scope: anonymous or unauthorized
	InvalidScopeIsAnonymous bool
	// Disable authorization - it will allow all requests and UserInfo will be always nil
	Disabled bool
}

Options is a configuration container to setup Authorization middleware.

func OptionsFromViper added in v0.3.0

func OptionsFromViper(prefix string) (options Options)

type UserInfo

type UserInfo struct {
	UserID string   `json:"uid,omitempty"`
	Email  string   `json:"email,omitempty"`
	Scopes []string `json:"scopes,omitempty"`
}

UserInfo information about authenticated user

func (*UserInfo) HasScope

func (ui *UserInfo) HasScope(scope string) bool

HasScope returns if given scope is included in user info

Jump to

Keyboard shortcuts

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