jwt

package
v0.0.0-...-cf6e08f Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Claims errors.
	ErrClaimDoesNotExist = errors.New("claim does not exist")
	ErrClaimNotAString   = errors.New("claim is not a string")
	ErrClaimNotAnInt64   = errors.New("claim is not an int64")

	// Token's errors.
	ErrTokenIsMalformed               = errors.New("malformed token")
	ErrTokenHasExpired                = errors.New("token has expired")
	ErrTokenInvalidSignature          = errors.New("invalid signature")
	ErrTokenUnableToSign              = errors.New("unable to sign token")
	ErrTokenNotValid                  = errors.New("token isn't valid yet")
	ErrTokenUnableToMarshallHeader    = errors.New("unable to marshal header")
	ErrTokenUnableToMarshallPayload   = errors.New("unable to marshal payload")
	ErrTokenUnableToDecodeB64Payload  = errors.New("unable to decode base64 payload")
	ErrTokenUnableToUnmarshallPayload = errors.New("unable to unmarshal payload json")
)

Functions

This section is empty.

Types

type Claims

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

func NewClaims

func NewClaims() *Claims

NewClaims returns a new map representing the claims with "iat" claim value.

func (*Claims) Contains

func (self *Claims) Contains(key string) bool

Contains returns if the claims map has given key.

func (Claims) Get

func (self Claims) Get(key string) (interface{}, error)

Get returns the claim in string form and returns an error if the specified claim doesn't exist.

func (*Claims) GetString

func (self *Claims) GetString(key string) (string, error)

GetTime attempts to return a claim as a time.

func (*Claims) GetTime

func (self *Claims) GetTime(key string) (time.Time, error)

GetTime attempts to return a claim as a time.

func (*Claims) Set

func (self *Claims) Set(key string, value interface{})

Set sets the claim in string form.

func (*Claims) SetTime

func (self *Claims) SetTime(key string, value time.Time)

SetTime sets the claim given to the specified time.

type Header struct {
	// Token type.
	Typ string

	// Message authentication code algorithm - the issuer can freely set an algorithm
	// to verify the signature on the token. However, some asymmetrical algorithms
	// pose security concerns.
	Alg string

	// Content type - this always is JWT.
	Cty string
}

Represents JWT Header. Contains important information for encrypting/decrypting.

type JWT

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

JWT is used to sign and validate a token.

func HmacSha256

func HmacSha256(key string) JWT

HmacSha256 returns the SingingMethod for HMAC with SHA256

func HmacSha384

func HmacSha384(key string) JWT

HmacSha384 returns the SigningMethod for HMAC with SHA384

func HmacSha512

func HmacSha512(key string) JWT

HmacSha512 returns the SigningMethod for HMAC with SHA512

func (*JWT) Decode

func (token *JWT) Decode(encoded string) (*Claims, error)

Decode returns a map representing the token's claims. DOESN'T validate the claims though.

func (*JWT) DecodeAndValidate

func (token *JWT) DecodeAndValidate(encoded string) (claims *Claims, err error)

DecodeAndValidate returns a map representing the token's claims, and it's valid.

func (*JWT) Encode

func (token *JWT) Encode(payload *Claims) (string, error)

Encode returns an encoded JWT token from a header, payload, and secret

func (*JWT) NewHeader

func (token *JWT) NewHeader() *Header

NewHeader returns a new Header object.

func (*JWT) Sign

func (token *JWT) Sign(unsignedToken string) ([]byte, error)

Sign signs the token with the given hash, and key

func (*JWT) Validate

func (token *JWT) Validate(encoded string) error

Validate verifies a token's validity. It returns nil if it is valid, and an error if invalid.

Jump to

Keyboard shortcuts

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