jwt

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2022 License: MIT Imports: 10 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 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 HasRole

func HasRole(ctx context.Context, role string) bool

func IsAuthenticated

func IsAuthenticated(ctx context.Context) bool

func JwtValidator

func JwtValidator(next http.Handler) http.Handler

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, username string, password string) 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 {
	// add any custom claim fields here so you can parse them
	Global GlobalClaims `json:"global"`
}

type GlobalClaims

type GlobalClaims struct {
	Name  string   `json:"name"`
	Roles []string `json:"roles"`
}

Jump to

Keyboard shortcuts

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