Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidToken indicates a malformed or unreadable token. ErrInvalidToken = errors.New("auth: invalid token") // ErrInvalidSignature indicates the token signature verification failed. ErrInvalidSignature = errors.New("auth: invalid signature") // ErrExpiredToken indicates the token has passed its expiration time. ErrExpiredToken = errors.New("auth: token expired") // ErrUnknownKeyID indicates the key ID in the token is not recognized. ErrUnknownKeyID = errors.New("auth: unknown key id") )
Functions ¶
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm identifies a signing algorithm.
const ( // AlgHMACSHA256 signs tokens using HMAC-SHA256. AlgHMACSHA256 Algorithm = "HS256" // AlgRS256 signs tokens using RSA-PKCS1v15 with SHA-256. AlgRS256 Algorithm = "RS256" // AlgES256 signs tokens using ECDSA with P-256 and SHA-256. AlgES256 Algorithm = "ES256" // AlgEdDSA signs tokens using Ed25519. AlgEdDSA Algorithm = "EdDSA" )
type Key ¶
type Key struct {
ID string
Secret []byte
Algorithm Algorithm
Private crypto.PrivateKey
Public crypto.PublicKey
}
Key holds signing key material.
type Payload ¶
Payload holds the claims for a simple token.
func VerifyToken ¶
VerifyToken verifies and decodes a HMAC-SHA256 token.
type SignedToken ¶
SignedToken holds a token string with its key ID and raw payload.
type StandardClaims ¶
type StandardClaims struct {
Sub string `json:"sub"`
Exp int64 `json:"exp"`
Iat int64 `json:"iat,omitempty"`
Jti string `json:"jti,omitempty"`
Iss string `json:"iss,omitempty"`
Aud string `json:"aud,omitempty"`
}
StandardClaims holds common JWT-like claims.
func (StandardClaims) Valid ¶
func (c StandardClaims) Valid() error
type TokenService ¶
type TokenService interface {
Sign(claims Claims) (*SignedToken, error)
Verify(token string) (Claims, error)
}
TokenService signs and verifies tokens.
func NewService ¶
func NewService(keys ...Key) TokenService
NewService creates a TokenService with one or more keys.
Click to show internal directories.
Click to hide internal directories.