jwt

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(elements map[string]interface{}) (result map[string]interface{})

Copy will copy all elements in a map and return a new representational map

func Filter

func Filter(elements map[string]interface{}, keys ...string) map[string]interface{}

Filter will filter out elemets based on keys in a given input map na key-slice

func ToString

func ToString(i interface{}) string

ToString will return a string representation of a map

func ToTime

func ToTime(i interface{}) time.Time

ToTime will try to convert a given input to a time.Time structure

Types

type Headers

type Headers struct {
	Extra map[string]interface{}
}

Headers is the jwt headers

func NewHeaders added in v0.19.0

func NewHeaders() *Headers

func (*Headers) Add

func (h *Headers) Add(key string, value interface{})

Add will add a key-value pair to the extra field

func (*Headers) Get

func (h *Headers) Get(key string) interface{}

Get will get a value from the extra field based on a given key

func (*Headers) ToMap

func (h *Headers) ToMap() map[string]interface{}

ToMap will transform the headers to a map structure

func (Headers) ToMapClaims added in v0.3.0

func (h Headers) ToMapClaims() jwt.MapClaims

ToMapClaims will return a jwt-go MapClaims representaion

type IDTokenClaims

type IDTokenClaims struct {
	JTI                                 string
	Issuer                              string
	Subject                             string
	Audience                            []string
	Nonce                               string
	ExpiresAt                           time.Time
	IssuedAt                            time.Time
	RequestedAt                         time.Time
	AuthTime                            time.Time
	AccessTokenHash                     string
	AuthenticationContextClassReference string
	CodeHash                            string
	Extra                               map[string]interface{}
}

IDTokenClaims represent the claims used in open id connect requests

func (*IDTokenClaims) Add

func (c *IDTokenClaims) Add(key string, value interface{})

Add will add a key-value pair to the extra field

func (*IDTokenClaims) Get

func (c *IDTokenClaims) Get(key string) interface{}

Get will get a value from the extra field based on a given key

func (*IDTokenClaims) ToMap

func (c *IDTokenClaims) ToMap() map[string]interface{}

ToMap will transform the headers to a map structure

func (IDTokenClaims) ToMapClaims added in v0.3.0

func (c IDTokenClaims) ToMapClaims() jwt.MapClaims

ToMapClaims will return a jwt-go MapClaims representation

type JWTClaims

type JWTClaims struct {
	Subject   string
	Issuer    string
	Audience  []string
	JTI       string
	IssuedAt  time.Time
	NotBefore time.Time
	ExpiresAt time.Time
	Scope     []string
	Extra     map[string]interface{}
}

JWTClaims represent a token's claims.

func (*JWTClaims) Add

func (c *JWTClaims) Add(key string, value interface{})

Add will add a key-value pair to the extra field

func (*JWTClaims) FromMap added in v0.6.17

func (c *JWTClaims) FromMap(m map[string]interface{})

FromMap will set the claims based on a mapping

func (*JWTClaims) FromMapClaims added in v0.6.17

func (c *JWTClaims) FromMapClaims(mc jwt.MapClaims)

FromMapClaims will populate claims from a jwt-go MapClaims representation

func (JWTClaims) Get

func (c JWTClaims) Get(key string) interface{}

Get will get a value from the extra field based on a given key

func (*JWTClaims) ToMap

func (c *JWTClaims) ToMap() map[string]interface{}

ToMap will transform the headers to a map structure

func (JWTClaims) ToMapClaims added in v0.3.0

func (c JWTClaims) ToMapClaims() jwt.MapClaims

ToMapClaims will return a jwt-go MapClaims representation

type JWTStrategy added in v0.19.0

type JWTStrategy interface {
	Generate(claims jwt.Claims, header Mapper) (string, string, error)
	Validate(token string) (string, error)
	GetSignature(token string) (string, error)
	Hash(in []byte) ([]byte, error)
	Decode(token string) (*jwt.Token, error)
	GetSigningMethodLength() int
}

type Mapper

type Mapper interface {
	ToMap() map[string]interface{}
	Add(key string, value interface{})
	Get(key string) interface{}
}

Mapper is the interface used internally to map key-value pairs

type RS256JWTStrategy

type RS256JWTStrategy struct {
	PrivateKey *rsa.PrivateKey
}

RS256JWTStrategy is responsible for generating and validating JWT challenges

func (*RS256JWTStrategy) Decode

func (j *RS256JWTStrategy) Decode(token string) (*jwt.Token, error)

Decode will decode a JWT token

func (*RS256JWTStrategy) Generate

func (j *RS256JWTStrategy) Generate(claims jwt.Claims, header Mapper) (string, string, error)

Generate generates a new authorize code or returns an error. set secret

func (*RS256JWTStrategy) GetSignature

func (j *RS256JWTStrategy) GetSignature(token string) (string, error)

GetSignature will return the signature of a token

func (*RS256JWTStrategy) GetSigningMethodLength

func (j *RS256JWTStrategy) GetSigningMethodLength() int

GetSigningMethodLength will return the length of the signing method

func (*RS256JWTStrategy) Hash

func (j *RS256JWTStrategy) Hash(in []byte) ([]byte, error)

Hash will return a given hash based on the byte input or an error upon fail

func (*RS256JWTStrategy) Validate

func (j *RS256JWTStrategy) Validate(token string) (string, error)

Validate validates a token and returns its signature or an error if the token is not valid.

Jump to

Keyboard shortcuts

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