jwt

package
v0.0.66 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package jwt provides the logic for reading and validating JWT tokens

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUserClaimFromContext

func GetUserClaimFromContext[T any](ctx context.Context, claim string) (T, bool)

GetUserClaimFromContext returns the specified claim from the user subject in the context if found and of the correct type

func GetUserEmailFromContext

func GetUserEmailFromContext(ctx context.Context) (string, error)

GetUserEmailFromContext returns the user email from the context, or an empty string

func GetUserSubjectFromContext

func GetUserSubjectFromContext(ctx context.Context) string

GetUserSubjectFromContext returns the user subject from the context, or nil

func GetUserTokenFromContext

func GetUserTokenFromContext(ctx context.Context) (openid.Token, error)

GetUserTokenFromContext returns the user token from the context

func WithAuthTokenContext

func WithAuthTokenContext(ctx context.Context, token openid.Token) context.Context

WithAuthTokenContext stores the specified user-identifying token in the context.

Types

type JwkSetJwtValidator

type JwkSetJwtValidator struct {
	// contains filtered or unexported fields
}

JwkSetJwtValidator is a JWT validator that uses a JWK set URL to validate the tokens

func (*JwkSetJwtValidator) ParseAndValidate

func (j *JwkSetJwtValidator) ParseAndValidate(tokenString string) (openid.Token, error)

ParseAndValidate validates a token string and returns an openID token, or an error if the token is invalid

type KeySetCache

type KeySetCache struct {
	// contains filtered or unexported fields
}

KeySetCache is a KeySetFetcher that fetches the JWK set from a cache

func (*KeySetCache) GetKeySet

func (k *KeySetCache) GetKeySet() (jwk.Set, error)

GetKeySet returns the caches JWK set

type KeySetFetcher

type KeySetFetcher interface {
	GetKeySet() (jwk.Set, error)
}

KeySetFetcher provides the functions to fetch a JWK set

type Validator

type Validator interface {
	ParseAndValidate(tokenString string) (openid.Token, error)
}

Validator provides the functions to validate a JWT

func NewJwtValidator

func NewJwtValidator(ctx context.Context, jwksUrl string, issUrl string, aud string) (Validator, error)

NewJwtValidator creates a new JWT validator that uses a JWK set URL to validate the tokens

Directories

Path Synopsis
Package mock_jwt is a generated GoMock package.
Package mock_jwt is a generated GoMock package.
Package noop provides a no-op implementation of the Validator interface
Package noop provides a no-op implementation of the Validator interface

Jump to

Keyboard shortcuts

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