echojwtx

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 6

Documentation

Overview

Package echojwtx implements echo-jwt middleware with additional helpers for setting the JWT Subject as an actor context value.

Index

Constants

View Source
const (
	// ActorKey defines the context key an actor is stored in for an echo context
	ActorKey = "actor"

	// DefaultHTTPClientStorageOptionRefreshInterval defines the frequency at which the jwks file is refreshed.
	DefaultHTTPClientStorageOptionRefreshInterval = time.Hour

	// DefaultHTTPClientStorageOptionHTTPTimeout limits the runtime of a reload of jwks.
	DefaultHTTPClientStorageOptionHTTPTimeout = 10 * time.Second

	// DefaultRateLimitWaitMax is the default timeout for waiting for rate limiting to end.
	DefaultRateLimitWaitMax = time.Minute
)
View Source
const (
	// DefaultOIDCJWKSRemoteTimeout defines the default timeout for fetching the OIDC JWKS file.
	DefaultOIDCJWKSRemoteTimeout = 5 * time.Second
)

Variables

View Source
var (
	// ActorCtxKey defines the context key an actor is stored in for a plain context
	ActorCtxKey = actorContext{}

	// ErrJWKSURIMissing is returned when the jwks_uri field is not found in the issuer's oidc well-known configuration.
	ErrJWKSURIMissing = errors.New("jwks_uri missing from oidc provider")
)

Functions

func Actor

func Actor(c echo.Context) string

Actor retrieves the ActorKey from echo Context.

func MustViperFlags

func MustViperFlags(v *viper.Viper, flags *pflag.FlagSet)

MustViperFlags adds jwks-uri to the provided flagset and binds to viper jwks.uri.

Types

type Auth

type Auth struct {

	// JWTConfig configuration for handling JWT validation.
	JWTConfig echojwt.Config

	// HTTPClientStorageOptions configuration for fetching JWKS.
	HTTPClientStorageOptions jwkset.HTTPClientStorageOptions
	// contains filtered or unexported fields
}

Auth handles JWT Authentication as echo middleware.

func NewAuth

func NewAuth(ctx context.Context, config AuthConfig, options ...Opts) (*Auth, error)

NewAuth creates a new auth middleware handler for JWTs using JWKS.

func (*Auth) Middleware

func (a *Auth) Middleware() echo.MiddlewareFunc

Middleware returns echo middleware for validation jwt tokens.

type AuthConfig

type AuthConfig struct {
	// Issuer is the Auth Issuer
	Issuer string `mapstructure:"issuer"`

	// Audience is the Auth Audience
	Audience string `mapstructure:"audience"`

	// RefreshTimeout is the timeout for fetching the JWKS from the issuer.
	RefreshTimeout time.Duration `mapstructure:"refresh_timeout"`

	// RateLimitWaitMax is the timeout for waiting for rate limiting to end.
	RateLimitWaitMax time.Duration `mapstructure:"rate_limit_wait_max"`
}

AuthConfig provides configuration for JWT validation using JWKS.

type Opts added in v0.2.0

type Opts func(*Auth)

Opts defines options for the Auth middleware.

func WithHTTPClientStorageOptions added in v0.5.0

func WithHTTPClientStorageOptions(options jwkset.HTTPClientStorageOptions) Opts

WithHTTPClientStorageOptions sets the HTTPClientStorageOptions for the auth middleware.

func WithJWTConfig added in v0.2.0

func WithJWTConfig(jwtConfig echojwt.Config) Opts

WithJWTConfig sets the JWTConfig for the auth middleware.

func WithLogger added in v0.2.0

func WithLogger(logger *zap.Logger) Opts

WithLogger sets the logger for the auth middleware.

Jump to

Keyboard shortcuts

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