auth

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2025 License: GPL-3.0 Imports: 11 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 FailHandlerFn,
	) func(next http.Handler) http.Handler
	AuthenticateFromHeader(
		token gojwttoken.Token,
	) func(next http.Handler) http.Handler
	AuthenticateFromCookie(
		token gojwttoken.Token,
		cookieRefreshTokenName,
		cookieAccessTokenName string,
		refreshTokenFn RefreshTokenFn,
	) func(next http.Handler) http.Handler
}

Authenticator interface

type FailHandlerFn added in v0.10.0

type FailHandlerFn func(
	w http.ResponseWriter,
	err error,
	errorCode *string,
)

FailHandlerFn defines the function signature for handling authentication failures

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

Parameters:

  • validator: The JWT validator service
  • handler: The HTTP handler to handle errors

Returns:

  • *Middleware: The authentication middleware

func (*Middleware) Authenticate

func (m *Middleware) Authenticate(
	token gojwttoken.Token,
	rawToken string,
	failHandler FailHandlerFn,
) func(next http.Handler) http.Handler

Authenticate return the middleware function that authenticates the request

Parameters:

  • token: The type of token to authenticate (access or refresh)
  • rawToken: The raw JWT token string
  • failHandler: The function to handle authentication failures

Returns:

  • func(next http.Handler) http.Handler: The middleware function

func (*Middleware) AuthenticateFromCookie added in v0.8.0

func (m *Middleware) AuthenticateFromCookie(
	token gojwttoken.Token,
	cookieRefreshTokenName,
	cookieAccessTokenName string,
	refreshTokenFn RefreshTokenFn,
) func(next http.Handler) http.Handler

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

Parameters:

  • token: The type of token to authenticate (access or refresh)
  • cookieRefreshTokenName: The name of the cookie that contains the refresh token
  • cookieAccessTokenName: The name of the cookie that contains the access token
  • refreshTokenFn: The function to refresh the access token using the refresh token

Returns:

  • func(next http.Handler) http.Handler: The middleware function

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

Parameters:

  • token: The type of token to authenticate (access or refresh)

Returns:

  • func(next http.Handler) http.Handler: The middleware function

type RefreshTokenFn added in v0.10.0

type RefreshTokenFn func(
	w http.ResponseWriter,
	r *http.Request,
) (map[gojwttoken.Token]string, error)

RefreshTokenFn defines the function signature for refreshing tokens

Jump to

Keyboard shortcuts

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