jwt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 13 Imported by: 1

README

jwt

Build Status

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedToken = errors.New("malformed token")
	ErrInvalidClaims  = errors.New("invalid claims")
	ErrInvalidSign    = errors.New("invalid sign")
	ErrWrongAlgorithm = errors.New("wrong algorithm")
	ErrExpiredToken   = errors.New("expired token")
)

Functions

func New

func New(key []byte, algo *Algorithm, claims *Claims) ([]byte, error)

func NewHS256

func NewHS256(key []byte, claims *Claims) ([]byte, error)

func NewHS256Custom

func NewHS256Custom(key []byte, claims interface{}) ([]byte, error)

func NewHS384

func NewHS384(key []byte, claims *Claims) ([]byte, error)

func NewHS384Custom

func NewHS384Custom(key []byte, claims interface{}) ([]byte, error)

func NewHS512

func NewHS512(key []byte, claims *Claims) ([]byte, error)

func NewHS512Custom

func NewHS512Custom(key []byte, claims interface{}) ([]byte, error)

func NewWithCustom

func NewWithCustom(key []byte, algo *Algorithm, claims interface{}) ([]byte, error)

func Parse

func Parse(token []byte, header *Header, claims *Claims) ([]byte, []byte, error)

func ParseAndValidate

func ParseAndValidate(token, key []byte, algo *Algorithm, claims *Claims) error

func ParseAndValidateCustom

func ParseAndValidateCustom(token, key []byte, algo *Algorithm, claims interface{}, validator ValidatorFunction) error

func ParseCustom

func ParseCustom(token []byte, header *Header, claims interface{}) ([]byte, []byte, error)

func ParseHS256

func ParseHS256(key, token []byte, claims *Claims) error

func ParseHS256Custom

func ParseHS256Custom(key, token []byte, claims interface{}, validator ValidatorFunction) error

func ParseHS384

func ParseHS384(key, token []byte, claims *Claims) error

func ParseHS384Custom

func ParseHS384Custom(key, token []byte, claims interface{}, validator ValidatorFunction) error

func ParseHS512

func ParseHS512(key, token []byte, claims *Claims) error

func ParseHS512Custom

func ParseHS512Custom(key, token []byte, claims interface{}, validator ValidatorFunction) error

func Verify

func Verify(algo *Algorithm, message, sign, key []byte) error

Types

type Algorithm

type Algorithm struct {
	Name string
	Hash func() hash.Hash
}

type Claims

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

func (*Claims) CheckAud

func (c *Claims) CheckAud(check string) bool

func (*Claims) CheckExp

func (c *Claims) CheckExp(check int64) bool

func (*Claims) CheckIss

func (c *Claims) CheckIss(check string) bool

func (*Claims) CheckNbf

func (c *Claims) CheckNbf(check int64) bool

func (*Claims) Decode

func (c *Claims) Decode(data []byte) error

func (*Claims) Encode

func (c *Claims) Encode() (string, error)

func (Claims) MarshalEasyJSON

func (v Claims) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Claims) MarshalJSON

func (v Claims) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Claims) UnmarshalEasyJSON

func (v *Claims) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Claims) UnmarshalJSON

func (v *Claims) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Header struct {
	Algorithm string `json:"alg"`
	Type      string `json:"typ"`
}

func (*Header) Decode

func (h *Header) Decode(data []byte) error

func (*Header) Encode

func (h *Header) Encode() (string, error)

func (Header) MarshalEasyJSON

func (v Header) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Header) MarshalJSON

func (v Header) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Header) UnmarshalEasyJSON

func (v *Header) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Header) UnmarshalJSON

func (v *Header) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ValidatorFunction

type ValidatorFunction func(claims interface{}) bool

Jump to

Keyboard shortcuts

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