attjwtmiddleware

package
v0.112.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RobotAccountProviderKey is the key for robot account token provider
	RobotAccountProviderKey = "robotAccountProvider"
	// APITokenProviderKey is the key for api token provider
	APITokenProviderKey = "apiTokenProvider"
)

Variables

View Source
var (
	ErrMissingJwtToken           = errorsAPI.Unauthorized(reason, "JWT token is missing")
	ErrMissingKeyFunc            = errorsAPI.Unauthorized(reason, "keyFunc is missing")
	ErrMissingVerifyAudienceFunc = errorsAPI.Unauthorized(reason, "verifyAudienceFunc is missing")
	ErrTokenInvalid              = errorsAPI.Unauthorized(reason, "Token is invalid")
	ErrTokenExpired              = errorsAPI.Unauthorized(reason, "JWT token has expired")
	ErrTokenParseFail            = errorsAPI.Unauthorized(reason, "Fail to parse JWT token ")
	ErrUnSupportSigningMethod    = errorsAPI.Unauthorized(reason, "Wrong signing method")
	ErrWrongContext              = errorsAPI.Unauthorized(reason, "Wrong context for middleware")
)

Functions

func WithJWTMulti

func WithJWTMulti(opts ...JWTOption) middleware.Middleware

WithJWTMulti creates a custom JWT middleware that configured with different token providers tries to run all validations from an incoming token. If one of the providers matches the expected audience it gets parsed and sent down to the next middleware. If none matches an error is returned

Types

type JWTAuthContext

type JWTAuthContext struct {
	Claims      jwt.Claims
	ProviderKey string
	Token       string
}

func FromJWTAuthContext

func FromJWTAuthContext(ctx context.Context) (authContext JWTAuthContext, ok bool)

FromJWTAuthContext extract JWTAuthContext from context

type JWTOption

type JWTOption func(*options)

func NewAPITokenProvider

func NewAPITokenProvider(signingSecret string) JWTOption

NewAPITokenProvider return the configuration to validate and verify token issued for API Tokens

func NewRobotAccountProvider

func NewRobotAccountProvider(signingSecret string) JWTOption

NewRobotAccountProvider return the configuration to validate and verify token issued for Robot Accounts

type TokenProviderOption

type TokenProviderOption func(*providerOption)

func WithClaims

func WithClaims(f func() jwt.Claims) TokenProviderOption

func WithKeyFunc

func WithKeyFunc(keyFunc jwt.Keyfunc) TokenProviderOption

func WithSigningMethod

func WithSigningMethod(method jwt.SigningMethod) TokenProviderOption

func WithVerifyAudienceFunc

func WithVerifyAudienceFunc(f VerifyAudienceFunc) TokenProviderOption

type VerifyAudienceFunc

type VerifyAudienceFunc func(*jwt.Token) bool

Jump to

Keyboard shortcuts

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