router

package
v0.0.0-...-7f35424 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultExpiration = 30 * time.Second

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(headerValue string) (string, error)

ExtractToken extracts the token from the Authorization header.

func RequestLoggerMiddleware

func RequestLoggerMiddleware(logger logger.Logger) gin.HandlerFunc

func SetupRouter

func SetupRouter(useOIDCAuth bool, l logger.Logger, authMiddleware *AuthMiddleware) (*gin.Engine, error)

Types

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) JSON

func (gc *GinContext) JSON(code int, obj any)

JSON sends a JSON response.

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.

func NewGinRouter

func NewGinRouter() *GinRouter

NewGinRouter is a constructor for GinRouter.

func (*GinRouter) Serve

func (gr *GinRouter) Serve(address string) error

Serve starts the HTTP server at the specified address.

type RedisTokenCache

type RedisTokenCache struct {
	Client     *redis.Client
	Ctx        context.Context
	Expiration time.Duration
}

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.

type TokenCache

type TokenCache interface {
	Get(token string) (bool, error)
	Set(token string) error
}

TokenCache is an interface for caching tokens.

func NewRedisTokenCache

func NewRedisTokenCache(addr string, password string, db int, expiration time.Duration) TokenCache

Jump to

Keyboard shortcuts

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