auth

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthenticated      = errors.New("user is unauthenticated, cannot continue with the request")
	ErrFailedToRefreshToken = errors.New("failed to refresh token")
	ErrInvalidJWTClaims     = errors.New("invalid JWT claims")
)

Functions

func FindAuthorizationToken

func FindAuthorizationToken(header http.Header, customName, cookieName *string) (token string, err error)

FindAuthorizationToken extracts the authorization token from the HTTP headers.

Parameters:

  • header: the HTTP headers to extract the token from
  • customName: optional custom header name to check for the token
  • cookieName: the name of the cookie to check for the token

Returns:

- string: the extracted authorization token, or an empty string if not found - error: if there was an error during extraction

Types

type Authenticator

type Authenticator interface {
	Authenticate() connect.UnaryInterceptorFunc
}

Authenticator interface

type Interceptor

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

Interceptor is the authentication interceptor

func NewInterceptor

func NewInterceptor(
	validator gojwtvalidator.Validator,
	interceptions map[string]*gojwttoken.Token,
	options *Options,
	logger *slog.Logger,
) (*Interceptor, error)

NewInterceptor creates a new authentication interceptor

Parameters:

  • validator: The JWT validator service (if nil, no validation will be done, can be used for gRPC gateways)
  • interceptions: The map of method names to token types to intercept
  • options: The options for the authentication interceptor (can be nil)
  • logger: The logger for the interceptor (can be nil)

Returns:

  • *Interceptor: The authentication middleware

func (Interceptor) Authenticate

func (i Interceptor) Authenticate() connect.UnaryInterceptorFunc

Authenticate is a unary server interceptor that extracts an authentication token

type Options

type Options struct {
	// CustomRefreshTokenName is the custom name for the refresh token (if nil, the default name will be used)
	CustomRefreshTokenName *string

	// CustomAccessTokenName is the custom name for the access token (if nil, the default name will be used)
	CustomAccessTokenName *string

	// RefreshTokenFn is the function to refresh the access token using the refresh token
	RefreshTokenFn RefreshTokenFn
}

Options is the options for the authentication interceptor

type RefreshTokenFn

type RefreshTokenFn func(
	ctx context.Context,
) error

RefreshTokenFn defines the function signature for refreshing tokens. NOTE: It should obtain the refresh token from the context and it should set the issued tokens in the context.

Jump to

Keyboard shortcuts

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