fwauth

package
v0.0.0-...-418145e Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenMissing is the error value that it's returned when
	// a token is not found based on the token extractor.
	ErrTokenMissing = errors.New("required authorization token not found")
)

Functions

func FromAuthHeader

func FromAuthHeader(ctx iris.Context) (string, error)

FromAuthHeader is a "TokenExtractor" that takes a give context and extracts the JWT token from the Authorization header.

func OnError

func OnError(ctx iris.Context, err error)

OnError is the default error handler. Use it to change the behavior for each error. See `Config.ErrorHandler`.

Types

type CasdoorOptions

type CasdoorOptions struct {
	casdoor.CasdoorOptions

	// The function that will be called when there's an error validating the token
	// Default value:
	ErrorHandler errorHandler
	// A function that extracts the token from the request
	// Default: FromAuthHeader (i.e., from Authorization header as bearer token)
	Extractor TokenExtractor
}

type Middleware

type Middleware struct {
	Options CasdoorOptions
}

func GetCasdoorMiddleware

func GetCasdoorMiddleware() *Middleware

func New

func New(opts ...CasdoorOptions) *Middleware

func (*Middleware) CheckJWT

func (m *Middleware) CheckJWT(ctx iris.Context) error

func (*Middleware) Get

func (m *Middleware) Get(ctx iris.Context) *casdoorsdk.Claims

Get returns the user (&token) information for this client/request

func (*Middleware) GetUserClaims

func (m *Middleware) GetUserClaims(ctx iris.Context) *casdoorsdk.Claims

func (*Middleware) Serve

func (m *Middleware) Serve(ctx iris.Context)

Serve the middleware's action

type TokenExtractor

type TokenExtractor func(iris.Context) (string, error)

TokenExtractor is a function that takes a context as input and returns either a token or an error. An error should only be returned if an attempt to specify a token was found, but the information was somehow incorrectly formed. In the case where a token is simply not present, this should not be treated as an error. An empty string should be returned in that case.

func FromFirst

func FromFirst(extractors ...TokenExtractor) TokenExtractor

FromFirst returns a function that runs multiple token extractors and takes the first token it finds

func FromHeader

func FromHeader(key string) TokenExtractor

FromHeader is a "TokenExtractor" that takes a give context and extracts the specified key value from header.

func FromParameter

func FromParameter(param string) TokenExtractor

FromParameter returns a function that extracts the token from the specified query string parameter

Jump to

Keyboard shortcuts

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