Documentation ¶
Overview ¶
Package jwt is able to generate and validate json web tokens. Follows https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32
Index ¶
- func Copy(elements map[string]interface{}) (result map[string]interface{})
- func Filter(elements map[string]interface{}, keys ...string) map[string]interface{}
- func ToString(i interface{}) string
- func ToTime(i interface{}) time.Time
- type Headers
- type IDTokenClaims
- type JWTClaims
- type Mapper
- type RS256JWTStrategy
- func (j *RS256JWTStrategy) Decode(token string) (*jwt.Token, error)
- func (j *RS256JWTStrategy) Generate(claims jwt.Claims, header Mapper) (string, string, error)
- func (j *RS256JWTStrategy) GetSignature(token string) (string, error)
- func (j *RS256JWTStrategy) GetSigningMethodLength() int
- func (j *RS256JWTStrategy) Hash(in []byte) ([]byte, error)
- func (j *RS256JWTStrategy) Validate(token string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Headers ¶
type Headers struct {
Extra map[string]interface{}
}
Headers is the jwt headers
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 { Issuer string Subject string Audience string Nonce string ExpiresAt time.Time IssuedAt time.Time AuthTime time.Time AccessTokenHash 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 representaion
type JWTClaims ¶
type JWTClaims struct { Subject string Issuer string Audience string JTI string IssuedAt time.Time NotBefore time.Time ExpiresAt time.Time Extra map[string]interface{} }
JWTClaims represent a token's claims.
func (JWTClaims) ToMapClaims ¶ added in v0.3.0
func (c JWTClaims) ToMapClaims() jwt.MapClaims
ToMapClaims will return a jwt-go MapClaims representaion
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