jwt

package
v0.0.0-...-f1b04be Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package jwt is a Go implementation of JSON Web Tokens: http://self-issued.info/docs/draft-jones-json-web-token.html.

See the exemplas for usage.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAlgorithm = errors.New("jwt: invalid algorithm")

ErrInvalidAlgorithm is returned when the token header key alg doesn't match

View Source
var ErrInvalidAudience = errors.New("jwt: invalid audience")

ErrInvalidAudience is returned when the claims.Audience doesn't match

View Source
var ErrInvalidIssuer = errors.New("jwt: invalid issuer")

ErrInvalidIssuer is returned when the claims.Issuer doesn't match

View Source
var ErrInvalidNumberOfSegments = errors.New("jwt: token contains an invalid number of segments")

ErrInvalidNumberOfSegments is returned when the token has less than 3 parts

View Source
var ErrInvalidSignature = errors.New("jwt: invalid signature")

ErrInvalidSignature is returned when the token signature doesn't match

View Source
var ErrInvalidSubject = errors.New("jwt: invalid subject")

ErrInvalidSubject is returned when the claims.Subject doesn't match

View Source
var ErrMalformedTokenClaims = errors.New("jwt: malformed token claims string")

ErrMalformedTokenClaims is returned when a error ocurrend with the jsaon Unmarshalling from token claims segment

View Source
var ErrMalformedTokenHeader = errors.New("jwt: malformed token header string")

ErrMalformedTokenHeader is returned when a error ocurrend with the jsaon Unmarshalling from token head segment

View Source
var ErrTokenExpired = errors.New("jwt: token expired")

ErrTokenExpired is used when the token has a claims.ExpiresAt < now

View Source
var ErrTokenNotValidYet = errors.New("jwt: token is not valid yet")

ErrTokenNotValidYet is returned when the client try to use a token before the claims.NotBefore time

View Source
var ErrTokenUsedBeforeIssued = errors.New("jwt: token used before issued")

ErrTokenUsedBeforeIssued is returned when the client try to use a token with now <= claims.IssuedAt >= now.

Functions

This section is empty.

Types

type Claims

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

Claims is a structured version of Claims Section, as referenced at https://tools.ietf.org/html/rfc7519#section-4.1

type JWT

type JWT struct {
	Audience string
	Issuer   string
	Subject  string
	AlgName  string
	Key      []byte
}

JWT contains the main api

func New

func New(audience string, issuer string, subject string, key string) *JWT

New allocates and returns a new JWT.

func (*JWT) NewToken

func (jwt *JWT) NewToken(id string, plusExpire int64) Token

NewToken creates a new token with the specified id and expiration delta

func (*JWT) ParseString

func (jwt *JWT) ParseString(tokenString string) (*Token, error)

ParseString allocates and returns a new Token based on a JWT signed token string

func (*JWT) SignedString

func (jwt *JWT) SignedString(t Token) (string, error)

SignedString returns the complete, signed token

type Token

type Token struct {
	Raw       string
	Header    map[string]string
	Claims    Claims
	Signature string
	Valid     bool
}

Token is a struct that maps all parts of a JWT Token. Different fields will be used depending on whether you're creating or parsing/verifying a token.

Jump to

Keyboard shortcuts

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