echojwtx

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 17 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"

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

	// DefaultKeyFuncOptionRefreshRateLimit limits how frequently jwks is reloaded when a provided KID is not found.
	DefaultKeyFuncOptionRefreshRateLimit = 5 * time.Minute

	// DefaultKeyFuncOptionRefreshTimeout limits the runtime of a reload of jwks.
	DefaultKeyFuncOptionRefreshTimeout = 10 * time.Second
)
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

	// KeyFuncOptions configuration for fetching JWKS.
	KeyFuncOptions keyfunc.Options
	// 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"`
}

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 WithJWTConfig added in v0.2.0

func WithJWTConfig(jwtConfig echojwt.Config) Opts

WithJWTConfig sets the JWTConfig for the auth middleware.

func WithKeyFuncOptions added in v0.2.0

func WithKeyFuncOptions(keyFuncOptions keyfunc.Options) Opts

WithKeyFuncOptions sets the KeyFuncOptions 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