jwt

package module
v0.0.0-...-04f33d7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

README

gojwt

Proof of concept JWT encoding and decoding library for Go. This project is an experimental API for securely decoding JWT tokens where token signing algorithms and token validity is very strictly enforced with the aim of avoiding the security pitfalls described in https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/.

If you're looking for a stable and production ready JWT library for Go, you should look at https://github.com/dgrijalva/jwt-go or https://github.com/SermoDigital/jose.

License

Apache License 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken     = errors.New("token is not valid")
	ErrInvalidHeader    = errors.New("token has invalid header")
	ErrInvalidType      = errors.New("invalid token type")
	ErrInvalidAlgorithm = errors.New("invalid or unsupported signing algorithm")
	ErrInvalidTimestamp = errors.New("invalid timestamp")
	ErrMalformedToken   = errors.New("malformed token content")
	ErrContextNotSet    = errors.New("token context has not been set")
)

Errors related to JSON web tokens

Functions

This section is empty.

Types

type Token

type Token struct {
	Context tokencontext.Context   `json:"-"`
	Header  map[string]interface{} `json:"header,omitempty"`
	Payload map[string]interface{} `json:"payload,omitempty"`
}

func Decode

func Decode(ctx tokencontext.Context, str string) (t *Token, err error)

func NewToken

func NewToken(ctx tokencontext.Context) *Token

func (*Token) Algorithm

func (token *Token) Algorithm() string

func (*Token) Audience

func (token *Token) Audience() string

func (*Token) Decode

func (token *Token) Decode(tokenStr string) error

func (*Token) Encode

func (token *Token) Encode() (string, error)

func (*Token) Expiration

func (token *Token) Expiration() (time.Time, bool)

func (*Token) IssuedAt

func (token *Token) IssuedAt() (time.Time, bool)

func (*Token) Issuer

func (token *Token) Issuer() string

func (*Token) NotBefore

func (token *Token) NotBefore() (time.Time, bool)

func (*Token) SetAudience

func (token *Token) SetAudience(audience string)

func (*Token) SetClaim

func (token *Token) SetClaim(key string, value interface{})

func (*Token) SetExpiration

func (token *Token) SetExpiration(ts time.Time)

func (*Token) SetIssuedAt

func (token *Token) SetIssuedAt(ts time.Time)

func (*Token) SetIssuer

func (token *Token) SetIssuer(issuer string)

func (*Token) SetNotBefore

func (token *Token) SetNotBefore(ts time.Time)

func (*Token) SetSubject

func (token *Token) SetSubject(subject string)

func (*Token) String

func (token *Token) String() string

func (*Token) Subject

func (token *Token) Subject() string

func (*Token) Type

func (token *Token) Type() string

func (*Token) Valid

func (token *Token) Valid() bool

func (*Token) Validate

func (token *Token) Validate() error

func (*Token) VerifySignature

func (token *Token) VerifySignature(tokenStr string) error

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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