Documentation
¶
Index ¶
- Constants
- func ExtractToken(headerValue string) (string, error)
- func RegisterAuthErrCode(scenario AuthErrorScenario, errCode string)
- func RegisterAuthMsgID(scenario AuthErrorScenario, msgID int)
- func RegisterMiddlewareErrCode(scenario MiddlewareErrorScenario, errCode string)
- func RegisterMiddlewareMsgID(scenario MiddlewareErrorScenario, msgID int)
- func RequestLoggerMiddleware(logger logger.Logger) gin.HandlerFunc
- func SetDefaultErrCode(errCode string)
- func SetDefaultMsgID(msgID int)
- func SetupRouter(useOIDCAuth bool, l logger.Logger, authMiddleware *AuthMiddleware) (*gin.Engine, error)
- func TimeoutMiddleware(timeout time.Duration) gin.HandlerFunc
- type AuthErrorScenario
- type AuthMiddleware
- type GinContext
- type GinRouter
- type MiddlewareErrorScenario
- type RedisTokenCache
- type TokenCache
Constants ¶
const DefaultExpiration = 30 * time.Second
Variables ¶
This section is empty.
Functions ¶
func ExtractToken ¶
ExtractToken extracts the token from the Authorization header.
func RegisterAuthErrCode ¶ added in v0.10.0
func RegisterAuthErrCode(scenario AuthErrorScenario, errCode string)
RegisterAuthErrCode allows the registration of an error code for a specific AuthErrorScenario.
func RegisterAuthMsgID ¶ added in v0.10.0
func RegisterAuthMsgID(scenario AuthErrorScenario, msgID int)
RegisterAuthMsgID allows the registration of a message ID for a specific AuthErrorScenario.
func RegisterMiddlewareErrCode ¶ added in v0.11.0
func RegisterMiddlewareErrCode(scenario MiddlewareErrorScenario, errCode string)
func RegisterMiddlewareMsgID ¶ added in v0.11.0
func RegisterMiddlewareMsgID(scenario MiddlewareErrorScenario, msgID int)
func RequestLoggerMiddleware ¶ added in v0.4.0
func RequestLoggerMiddleware(logger logger.Logger) gin.HandlerFunc
func SetDefaultErrCode ¶ added in v0.10.0
func SetDefaultErrCode(errCode string)
SetDefaultErrCode allows external code to set a custom default error code.
func SetDefaultMsgID ¶ added in v0.10.0
func SetDefaultMsgID(msgID int)
SetDefaultMsgID allows external code to set a custom default message ID.
func SetupRouter ¶
func TimeoutMiddleware ¶ added in v0.11.0
func TimeoutMiddleware(timeout time.Duration) gin.HandlerFunc
Types ¶
type AuthErrorScenario ¶ added in v0.10.0
type AuthErrorScenario string
AuthErrorScenario defines a set of constants representing different error scenarios that can occur within the AuthMiddleware. These scenarios are used to map specific error conditions to message IDs and error codes.
const ( // TokenMissing indicates an error scenario where the expected authentication token is missing from the request. TokenMissing AuthErrorScenario = "TokenMissing" // TokenCacheFailed indicates an error scenario where an operation related to caching the token fails. TokenCacheFailed AuthErrorScenario = "TokenCacheFailed" // TokenVerificationFailed indicates an error scenario where the authentication token fails verification. TokenVerificationFailed AuthErrorScenario = "TokenVerificationFailed" )
type AuthMiddleware ¶
type AuthMiddleware struct { Verifier *oidc.IDTokenVerifier Cache TokenCache Logger logger.Logger }
func LoadAuthMiddleware ¶
func LoadAuthMiddleware(clientID string, providerURL string, cache TokenCache, l logger.Logger) (*AuthMiddleware, error)
func NewAuthMiddleware ¶
func NewAuthMiddleware(clientID string, provider *oidc.Provider, cache TokenCache, logger logger.Logger) (*AuthMiddleware, error)
func (*AuthMiddleware) MiddlewareFunc ¶
func (a *AuthMiddleware) MiddlewareFunc() gin.HandlerFunc
MiddlewareFunc returns a gin.HandlerFunc (middleware) that checks for a valid token.
type GinContext ¶
type GinContext struct {
// contains filtered or unexported fields
}
GinContext is an adapter that implements the Context interface for Gin.
func (*GinContext) Bind ¶
func (gc *GinContext) Bind(obj any) error
Bind binds the request body to obj.
func (*GinContext) BindJSON ¶
func (gc *GinContext) BindJSON(obj any) error
BindJSON binds the JSON request body into obj.
func (*GinContext) Request ¶
func (gc *GinContext) Request() *http.Request
Request returns the underlying http.Request.
type GinRouter ¶
type GinRouter struct {
// contains filtered or unexported fields
}
GinRouter implements the Router interface for Gin framework.
type MiddlewareErrorScenario ¶ added in v0.11.0
type MiddlewareErrorScenario string
const (
RequestTimeout MiddlewareErrorScenario = "RequestTimeout"
)
type RedisTokenCache ¶
RedisTokenCache is a Redis implementation of TokenCache.
func (*RedisTokenCache) Get ¶
func (r *RedisTokenCache) Get(token string) (bool, error)
Get gets a token from the cache.
func (*RedisTokenCache) Set ¶
func (r *RedisTokenCache) Set(token string) error
Set sets a token in the cache.