jwt

package
v2.17.3 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ClaimExpirationTime = "exp"
	ClaimNotBefore      = "nbf"
	ClaimIssuedAt       = "iat"
	ClaimAudience       = "aud"
	ClaimIssuer         = "iss"
	ClaimSubject        = "sub"
	ClaimScope          = "scope"
	ClaimID             = "jti"
	ClaimEmail          = "email"
	ClaimClientID       = "client_id"
	ClaimName           = "n"
)
View Source
const PlgdRequiredScope = "plgd:required:scope"

Variables

View Source
var (
	ErrMissingToken     = errors.New("missing token")
	ErrCannotParseToken = errors.New("could not parse token")
)
View Source
var ErrMissingRequiredScopes = errors.New("required scopes not found")
View Source
var ErrOwnerClaimInvalid = errors.New("owner claim is invalid")

Functions

This section is empty.

Types

type Claims

type Claims jwt.MapClaims

func ParseToken

func ParseToken(token string) (Claims, error)

func (Claims) GetAudience added in v2.16.3

func (c Claims) GetAudience() (jwt.ClaimStrings, error)

GetAudience returns the Audience ("aud") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetClientID added in v2.16.3

func (c Claims) GetClientID() (string, error)

GetClientID returns the ClientID ("client_id") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetDeviceID added in v2.16.3

func (c Claims) GetDeviceID(deviceIDClaim string) (string, error)

GetDeviceID returns the DeviceID ("device_id") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetEmail added in v2.16.3

func (c Claims) GetEmail() (string, error)

GetEmail returns the Email ("email") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetExpirationTime added in v2.16.3

func (c Claims) GetExpirationTime() (*jwt.NumericDate, error)

GetExpirationTime returns the Expiration Time ("exp") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetID added in v2.16.3

func (c Claims) GetID() (string, error)

GetID returns the ID ("jti") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetIssuedAt added in v2.16.3

func (c Claims) GetIssuedAt() (*jwt.NumericDate, error)

GetIssuedAt returns the Issued At ("iat") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetIssuer added in v2.16.3

func (c Claims) GetIssuer() (string, error)

GetIssuer returns the Issuer ("iss") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetName added in v2.16.3

func (c Claims) GetName() (string, error)

GetName returns the Name ("n") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetNotBefore added in v2.16.3

func (c Claims) GetNotBefore() (*jwt.NumericDate, error)

GetNotBefore returns the Not Before ("nbf") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetOwner added in v2.16.3

func (c Claims) GetOwner(ownerClaim string) (string, error)

GetOwner returns the Owner ("owner") claim. If the claim does not exist, an empty string is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetScope added in v2.16.3

func (c Claims) GetScope() (jwt.ClaimStrings, error)

GetScope returns the Scope ("scope") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) GetSubject added in v2.16.3

func (c Claims) GetSubject() (string, error)

GetSubject returns the Subject ("sub") claim. If the claim does not exist, nil is returned. If the claim has the wrong type, an error is returned.

func (Claims) ValidateOwnerClaim

func (c Claims) ValidateOwnerClaim(ownerClaim string, userID string) error

ValidateOwnerClaim validates that ownerClaim is set and that it matches given user ID

type KeyCache

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

func NewKeyCache

func NewKeyCache(url string, client *http.Client) *KeyCache

func (*KeyCache) FetchKeys

func (c *KeyCache) FetchKeys() error

func (*KeyCache) FetchKeysWithContext

func (c *KeyCache) FetchKeysWithContext(ctx context.Context) error

func (*KeyCache) GetKey

func (c *KeyCache) GetKey(token *jwt.Token) (interface{}, error)

func (*KeyCache) GetOrFetchKey

func (c *KeyCache) GetOrFetchKey(token *jwt.Token) (interface{}, error)

func (*KeyCache) GetOrFetchKeyWithContext

func (c *KeyCache) GetOrFetchKeyWithContext(ctx context.Context, token *jwt.Token) (interface{}, error)

func (*KeyCache) LookupKey

func (c *KeyCache) LookupKey(token *jwt.Token) (jwk.Key, error)

type ScopeClaims

type ScopeClaims Claims

func NewRegexpScopeClaims

func NewRegexpScopeClaims(scope ...*regexp.Regexp) *ScopeClaims

func NewScopeClaims

func NewScopeClaims(scope ...string) *ScopeClaims

func (*ScopeClaims) GetAudience added in v2.16.3

func (c *ScopeClaims) GetAudience() (jwt.ClaimStrings, error)

func (*ScopeClaims) GetExpirationTime added in v2.16.3

func (c *ScopeClaims) GetExpirationTime() (*jwt.NumericDate, error)

func (*ScopeClaims) GetIssuedAt added in v2.16.3

func (c *ScopeClaims) GetIssuedAt() (*jwt.NumericDate, error)

func (*ScopeClaims) GetIssuer added in v2.16.3

func (c *ScopeClaims) GetIssuer() (string, error)

func (*ScopeClaims) GetNotBefore added in v2.16.3

func (c *ScopeClaims) GetNotBefore() (*jwt.NumericDate, error)

func (*ScopeClaims) GetSubject added in v2.16.3

func (c *ScopeClaims) GetSubject() (string, error)

func (*ScopeClaims) Validate added in v2.16.3

func (c *ScopeClaims) Validate() error

type Validator

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

func NewValidator

func NewValidator(keyCache *KeyCache) *Validator

func (*Validator) Parse

func (v *Validator) Parse(token string) (jwt.MapClaims, error)

func (*Validator) ParseToken added in v2.16.3

func (v *Validator) ParseToken(token string) (*jwt.Token, error)

func (*Validator) ParseWithClaims

func (v *Validator) ParseWithClaims(token string, claims jwt.Claims) error

func (*Validator) ParseWithContext

func (v *Validator) ParseWithContext(ctx context.Context, token string) (jwt.MapClaims, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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