token

package
v0.0.0-...-721f978 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package token defines methods and types for using and validating Freyr tokens in JWT format.

Index

Constants

This section is empty.

Variables

View Source
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

func GenerateDeviceToken(t Source, exp time.Time, coreid, userEmail string) (string, error)

GenerateDeviceToken generates a JWT to be used by a Spark webhook registered with a core sending readings.

func GenerateWebToken

func GenerateWebToken(t Source, exp time.Time, userEmail string) (string, error)

GenerateWebToken generates a JWT to be used as a session token by a user accessing the API via a web browser.

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

func (t JWTTokenGen) GenerateToken(exp time.Time, claims Claims) (string, error)

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.

Jump to

Keyboard shortcuts

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