jwt

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RawTokenKey ctxJwtKeyType = 0
	ClaimsKey   ctxJwtKeyType = 1
)

Variables

View Source
var Now = time.Now

Now exported for testing

View Source
var RsaPublicKeys = make([]*rsa.PublicKey, 0)

Functions

func Email

func Email(ctx context.Context) string

func GetRawToken

func GetRawToken(ctx context.Context) string

GetRawToken returns the raw token from the given context if one is present.

Returns the empty string if the context contains no valid token.

func HasGroup

func HasGroup(ctx context.Context, group string, logMessage string, timestamp time.Time) apierrors.AnnotatedError

func IsAuthenticated

func IsAuthenticated(ctx context.Context, logMessage string, timestamp time.Time) apierrors.AnnotatedError

func JwtValidator

func JwtValidator(next http.Handler) http.Handler

func Name

func Name(ctx context.Context) string

func PutClaims

func PutClaims(ctx context.Context, claimsPtr *AllClaims) context.Context

PutClaims places a raw token in the context under the correct key.

Returns a child context with the token set.

Exposed for testing only.

func PutRawToken

func PutRawToken(ctx context.Context, rawToken string) context.Context

PutRawToken places a raw token in the context under the correct key.

Returns a child context with the token set.

Exposed for testing only.

func Setup

func Setup(publicKeyPEMs []string, config config.CustomConfiguration) error

func Subject

func Subject(ctx context.Context) string

Types

type AllClaims

type AllClaims struct {
	// maybe * ?
	jwt.RegisteredClaims
	CustomClaims
}

func GetClaims

func GetClaims(ctx context.Context) *AllClaims

GetClaims returns the raw token from the given context if one is present.

Returns the empty string if the context contains no valid token.

type CustomClaims

type CustomClaims struct {
	Name   string   `json:"name"`
	Email  string   `json:"email"`
	Groups []string `json:"groups"`
}

Jump to

Keyboard shortcuts

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