Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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, modeFlag *goflagsmode.Flag, 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
- modeFlag: The mode for the interceptor (can be nil)
- 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 ¶
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.