Documentation ¶
Overview ¶
Package token defines methods and types for using and validating Freyr tokens in JWT format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrorInvalidToken ValidationError = errors.New("Invalid Token") ErrorTokenExpired = errors.New("Token has expired") ErrorInvalidAlgorithm = errors.New("Token signed with invalid algorithm") )
Exported ValidationError 'constants'
Functions ¶
func GenerateDeviceToken ¶
GenerateDeviceToken generates a JWT to be used by a Spark webhook registered with a core sending readings.
Types ¶
type Claims ¶
type Claims map[string]interface{}
Claims is a type used to set claim values in a JWT.
func ValidateUserToken ¶
func ValidateUserToken(store models.SecretStore, jwtTokenString string) (Claims, error)
ValidateUserToken validates a JWT signed with a particular user's secret.
type JWTTokenGen ¶
type JWTTokenGen []byte
JWTTokenGen is a type used for generating signed JSON Web Tokens.
func (JWTTokenGen) GenerateToken ¶
GenerateToken returns a signed JSON Web Token with the set claims and expiration date.
func (JWTTokenGen) ValidateToken ¶
func (t JWTTokenGen) ValidateToken(tokenString string) (Claims, error)
ValidateToken verifies if a string is a valid JSON Web token, and was signed with the key used the TokenGen's key. If valid, it returns the token's claims.
type Source ¶
type Source interface { GenerateToken(exp time.Time, claims Claims) (string, error) ValidateToken(string) (Claims, error) }
Source is an interface representing types that can generate and validate JWT tokens. Typically a TokenSource holds a secret for signing or has access to keyed secrets e.g. user secrets.
type ValidationError ¶
type ValidationError error
ValidationError is used for errors related to validating tokens.