auth

package
v0.9.11 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeInvalidAuthorizationHeader *string
	ErrCodeInvalidTokenClaims         *string
	ErrCodeFailedToRefreshToken       *string
)
View Source
var (
	ErrNilAuthenticator           = errors.New("authenticator cannot be nil")
	ErrInvalidAuthorizationHeader = errors.New("invalid authorization header")
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Authenticate(
		token gojwttoken.Token,
		rawToken string,
		failHandler func(
			w http.ResponseWriter,
			err error,
			errorCode *string,
		),
		refreshTokenFn func(
			w http.ResponseWriter,
			r *http.Request,
		) error,
		authenticateFn func(next http.Handler) http.Handler,
	) func(next http.Handler) http.Handler
	AuthenticateFromHeader(
		token gojwttoken.Token,
	) func(next http.Handler) http.Handler
	AuthenticateFromCookie(
		token gojwttoken.Token,
		cookieName string,
		refreshTokenFn func(
			w http.ResponseWriter,
			r *http.Request,
		) error,
	) func(next http.Handler) http.Handler
}

Authenticator interface

type Middleware

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

Middleware struct is the authentication middleware

func NewMiddleware

func NewMiddleware(
	validator gojwtvalidator.Validator,
	handler gonethttphandler.Handler,
) (*Middleware, error)

NewMiddleware creates a new authentication middleware

func (*Middleware) Authenticate

func (m *Middleware) Authenticate(
	token gojwttoken.Token,
	rawToken string,
	failHandler func(
		w http.ResponseWriter,
		err error,
		errorCode *string,
	),
	refreshTokenFn func(
		w http.ResponseWriter,
		r *http.Request,
	) error,
	authenticateFn func(next http.Handler) http.Handler,
) func(next http.Handler) http.Handler

Authenticate return the middleware function that authenticates the request

func (*Middleware) AuthenticateFromCookie added in v0.8.0

func (m *Middleware) AuthenticateFromCookie(
	token gojwttoken.Token,
	cookieName string,
	refreshTokenFn func(
		w http.ResponseWriter,
		r *http.Request,
	) error,
) func(next http.Handler) http.Handler

AuthenticateFromCookie return the middleware function that authenticates the request from the cookie

func (*Middleware) AuthenticateFromHeader added in v0.8.0

func (m *Middleware) AuthenticateFromHeader(
	token gojwttoken.Token,
) func(next http.Handler) http.Handler

AuthenticateFromHeader return the middleware function that authenticates the request from the header

Jump to

Keyboard shortcuts

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