simplejwt

package module
v0.0.0-...-c26a47f Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidExpirationTime = errors.New("invalid expiration time")
	ErrInvalidNotBefore      = errors.New("invalid not before")
	ErrInvalidIssuedAt       = errors.New("invalid issued at")
)
View Source
var (
	ErrInvalidTokenString = errors.New("invalid token string")
	ErrAlgMissing         = errors.New("JOSE header is missing alg field")
	ErrUnknownAlg         = errors.New("unknown signing method")
)

Functions

func GetSigningAlgorithm

func GetSigningAlgorithm(name string) (algorithms.SigningAlgorithm, error)

GetSigningAlgorithm returns the signing algorithm for the given algorithm name.

Types

type Claims

type Claims interface {
	Valid(int64) error
	Get(key string) interface{}
}

Claims represents the a claims set.

type CustomClaims

type CustomClaims map[string]interface{}

CustomClaims represents a custom claims set.

func (CustomClaims) Get

func (cc CustomClaims) Get(key string) (value interface{})

func (CustomClaims) Valid

func (cc CustomClaims) Valid(t int64) error

Valid returns an error if the CustomClaims object is not valid. Otherwise nil is returned; indicating the claims set is valid.

type JOSEHeader

type JOSEHeader map[string]interface{}

JOSEHeader represents the JOSE header of a JWT. It is common, that only the typ and alg fields are set; identifying the algorithm used in generating the JWT's signature.

type RegisteredClaims

type RegisteredClaims struct {
	Issuer         string `json:"iss,omitempty"`
	Subject        string `json:"sub,omitempty"`
	Audience       string `json:"aud,omitempty"`
	ExpirationTime int64  `json:"exp,omitempty"`
	NotBefore      int64  `json:"nbf,omitempty"`
	IssuedAt       int64  `json:"iat,omitempty"`
	JWTID          string `json:"jti,omitempty"`
}

RegisteredClaims implements a claims set using the registered (standard) claims according to the IANA "JSON Web Token Claims" registry.

func (RegisteredClaims) Get

func (rc RegisteredClaims) Get(key string) (value interface{})

func (RegisteredClaims) Valid

func (rc RegisteredClaims) Valid(t int64) error

Valid returns an error if the RegisteredClaims object is not valid. Otherwise nil is returned; indicating the claims set is valid.

type Token

type Token struct {
	Header    JOSEHeader
	Claims    Claims
	Data      string
	Signature string
	Algorithm algorithms.SigningAlgorithm
}

Token represents a JSON Web Token (JWT).

func New

func New(claims Claims, alg algorithms.SigningAlgorithm) *Token

NewToken returns a new JWT instance.

func Parse

func Parse(tokenStr string) (*Token, error)

Parse returns a token parsed from the given token string.

func (*Token) Sign

func (t *Token) Sign(key []byte) (string, error)

Sign returns the signature of the JWT using the given key.

func (*Token) SigningString

func (t *Token) SigningString() (string, error)

SigningString returns the base64 encoded string for generating the signature of the JWT.

func (*Token) Valid

func (t *Token) Valid(key []byte) error

Valid returns nil if the token is valid using the given key. Otherwise, an error is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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