jwt

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package JWT contains functions required for JWT signing and validation.

Currently only PS512 algorithm is supported, more methods will be added in future releases.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Dat interface{} `json:"dat,omitempty"`
	*jwt.StandardClaims
}

Claims represents a custom claim where the dat section is used for custom data.

TODO: make this generic in 2.0

func NewClaims added in v1.2.0

func NewClaims() *Claims

NewClaims creates a new instance of the custom JWT claims.

TODO: make this generic in 2.0

func (*Claims) WithDat added in v1.2.0

func (c *Claims) WithDat(dat interface{}) *Claims

WithDat adds a dat claim to the JWT token.

TODO: make this generic in 2.0

func (*Claims) WithExpiry added in v1.2.0

func (c *Claims) WithExpiry(expiry time.Time) *Claims

WithExpiry updates the expify of the JWT token to the specified time.

TODO: make this generic in 2.0

type Manager

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

Manager is responsible for creating and validating JWT tokens.

Given that validating JWT comes with a hefty cost, internally, the manager caches already validated tokens, so if the same token is validated repeatedly, cached results will be returned.

func NewManager deprecated

func NewManager(publicKey *rsa.PublicKey, privateKey *rsa.PrivateKey) Manager

NewManager creates a new JWT client that signs and validates JWT tokens using the PS512 algorithm.

Deprecated: Instead of using this method, users of the library should use NewPS512Manager instead. The underlying source code has already been converted to use the new function, and all users should also do so.

This method will be removed in the 2.0 version stream when we implement generics.

func NewPS512Manager added in v1.2.0

func NewPS512Manager(publicKey *rsa.PublicKey, privateKey *rsa.PrivateKey) Manager

NewPS512Manager creates a new JWT client that signs and validates JWT tokens using the PS512 algorithm.

func (Manager) CreateCustom deprecated

func (m Manager) CreateCustom(dat interface{},
	expiresAt *time.Time) (<-chan string, <-chan error)

CreateCustom creates a JWT token with custom dat claim.

Deprecated: Instead of using this method, users of the library should create the Claims object separately and use the SignCustom function instead. The underlying source code has already been converted to use the new function, and all users should also do so.

This method will be removed in the 2.0 version stream when we implement generics.

func (Manager) ParseCustom added in v1.2.0

func (m Manager) ParseCustom(token string) (<-chan *Claims, <-chan error)

ParseCustom parses a JWT token with the claims and returns the claims of the token.

TODO: make this generic in 2.0

func (Manager) SignCustom added in v1.2.0

func (m Manager) SignCustom(claims *Claims) (<-chan string, <-chan error)

SignCustom signs the JWT token with the given claims.

TODO: make this generic in 2.0

func (Manager) ValidateCustom deprecated

func (m Manager) ValidateCustom(token string) (<-chan interface{}, <-chan error)

ValidateCustom validates a JWT token with a custom dat claim.

Deprecated: Instead of using this method, users of the library should use ParseCustom function instead, and subsequently work directly with the Claims object that the function returns. The underlying source code has already been converted to use the new function, and all users should also do so.

This method will be removed in the 2.0 version stream when we implement generics.

Jump to

Keyboard shortcuts

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