jwt

package
v0.0.0-...-9004257 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateKeys

func GenerateKeys(keyDir string) error

GenerateKeys generate and save the keys to disk

func Sign

func Sign(keyDir string, message []byte) ([]byte, error)

Sign function to sign a new key

func Verify

func Verify(keyDir string, message []byte, signature []byte) bool

Verify used to validate the incoming key

Types

type Claims

type Claims struct {
	// Subject or userid
	Sub string `json:"sub,omitempty"`
	// When the token will expire
	Exp int `json:"exp,omitempty"`
	// Token is not valid before this time
	Nbf int `json:"nbf,omitempty"`
	// When the token was issued
	Iat int `json:"iat,omitempty"`
}

Claims struct to hold various public data

func NewClaims

func NewClaims(duration int) *Claims

NewClaims returns a new default claims

func NewClaimsParse

func NewClaimsParse(message []byte) (*Claims, error)

NewClaimsParse creates a new claims from a string the message should be a base64.URLEncoded string

func (*Claims) Bytes

func (c *Claims) Bytes() ([]byte, error)

Bytes returns the bytes for the claims

func (*Claims) EncodedBytes

func (c *Claims) EncodedBytes() ([]byte, error)

EncodedBytes takes the bytes tring and url encodes it

func (*Claims) Parse

func (c *Claims) Parse(message []byte) error

Parse unmarshall claims from json

func (*Claims) Validate

func (c *Claims) Validate(t time.Time) bool

Validate checks the claims

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

Header struct to hold the header information

func NewHeader

func NewHeader() *Header

NewHeader returns a new default header

func NewHeaderParse

func NewHeaderParse(message []byte) (*Header, error)

NewHeaderParse function to create new JWT header message should be the base64.URLEncoded string

func (*Header) Bytes

func (h *Header) Bytes() ([]byte, error)

Bytes returns the bytes for the header

func (*Header) EncodedBytes

func (h *Header) EncodedBytes() ([]byte, error)

EncodedBytes takes the bytes string and url encodes it

func (*Header) Parse

func (h *Header) Parse(message []byte) error

Parse unmarshall header from json message should be the unparsed json string

func (*Header) Validate

func (h *Header) Validate() bool

Validate makes sure the header is in proper form

type JWT

type JWT struct {
	H *Header
	C *Claims
	// contains filtered or unexported fields
}

JWT struct holds the entire token

func NewJWT

func NewJWT(h Header, c Claims, configDir string) *JWT

NewJWT returns a new JWT with header and claims

func NewJWTParse

func NewJWTParse(message []byte) (*JWT, error)

NewJWTParse takes a jwt token string and parse it into a token message should be the unmodified base64.RawURLEncoded string

func (*JWT) EncodedBytesSignature

func (j *JWT) EncodedBytesSignature() []byte

EncodedBytesSignature returns the encoded byte string

func (*JWT) GenerateMessage

func (j *JWT) GenerateMessage() ([]byte, error)

GenerateMessage returns the full jwt token

func (*JWT) GenerateToken

func (j *JWT) GenerateToken() ([]byte, error)

GenerateToken takes all the components and spits out a token

func (*JWT) ValidateToken

func (j *JWT) ValidateToken() bool

ValidateToken checks the token claims at UTC time

func (*JWT) VerifyToken

func (j *JWT) VerifyToken(keyDir string) bool

VerifyToken checks the signature is valid

Jump to

Keyboard shortcuts

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