Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrTokenMalformed = errors.New("token is malformed") ErrTokenUnverifiable = errors.New("token is unverifiable") ErrTokenSignatureInvalid = errors.New("token signature is invalid") ErrSignatureInvalid = errors.New("signature is invalid") ErrInvalidKeyType = errors.New("key is of invalid type") )
Functions ¶
This section is empty.
Types ¶
type Keyfunc ¶
Keyfunc is used by Parse to supply the key for verification. The function receives the parsed but unverified Token (e.g. to read "alg" from header).
type MapClaims ¶
type MapClaims map[string]interface{}
MapClaims is a claims type that uses map[string]interface{} for JSON decoding. Used as the default claims type for parsing and creating tokens.
type SigningMethod ¶
type SigningMethod interface {
Verify(signingString string, sig []byte, key interface{}) error
Sign(signingString string, key interface{}) ([]byte, error)
Alg() string
}
SigningMethod is used to sign and verify tokens.
var SigningMethodHS256 SigningMethod = signingMethodHS256
SigningMethodHS256 is the HMAC-SHA256 signing method.
type SigningMethodHMAC ¶
type SigningMethodHMAC struct {
Name string
}
SigningMethodHMAC implements HS256.
func (*SigningMethodHMAC) Alg ¶
func (m *SigningMethodHMAC) Alg() string
type Token ¶
type Token struct {
Raw string
Method SigningMethod
Header map[string]interface{}
Claims MapClaims
Signature []byte
Valid bool
}
Token represents a JWT.
func NewWithClaims ¶
func NewWithClaims(method SigningMethod, claims MapClaims) *Token
NewWithClaims creates a new Token with the given signing method and claims.
func Parse ¶
Parse parses and verifies the JWT and returns the token. Only HS256 signature verification is supported.
func (*Token) EncodeSegment ¶
EncodeSegment encodes bytes to base64url without padding.
func (*Token) SignedString ¶
SignedString signs the token and returns the full JWT string.
func (*Token) SigningString ¶
SigningString returns the base64url(header).base64url(claims) string.