api

package
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrTokenInvalid is returned when the token provided is invalid
	ErrTokenInvalid = errors.New("token invalid")
	// ErrNoToken is returned if no token is supplied in the request.
	ErrNoToken = errors.New("token not found in request")
	// FOOTER is the footer used in the Paseto token
	FOOTER = envy.Get("PASETO_FOOTER", "LicenseServer")
)

Functions

func App added in v0.2.0

func App() *buffalo.App

App returns a new api group. It requires PASETO_KEY to be set.

func AuthenticateNonce added in v0.2.0

func AuthenticateNonce(next buffalo.Handler) buffalo.Handler

AuthenticateNonce checks if the nonce provided in the request matches the stored nonce. WARNING: Deletes token if the nonces mismatch.

func AuthenticateToken added in v0.2.0

func AuthenticateToken(options Options) buffalo.MiddlewareFunc

AuthenticateToken validates a PASETO token passed in the Authorization HTTP header with type 'Bearer'. Token jti needs to be stored as AuthToken in the db to be valid.

func GenerateToken

func GenerateToken(c buffalo.Context) error

GenerateToken generates a new token for the user

func SampleHandler

func SampleHandler(c buffalo.Context) error

SampleHandler is a dummy handler to test API authentication.

Types

type Error added in v0.2.0

type Error struct {
	Error string `json:"error"`
}

Error is a generic error struct with an error message.

type GenerateTokenPayload added in v0.2.0

type GenerateTokenPayload struct {
	LicenseID uuid.UUID `json:"license_id"`
	UserID    uuid.UUID `json:"user_id"`
	MachineID uuid.UUID `json:"machine_id"`
}

GenerateTokenPayload represents the expected json payload for token generation requests.

type GenerateTokenResult added in v0.2.0

type GenerateTokenResult struct {
	// Token is a Paseto token bound to a license allowing access to an application.
	Token string `json:"token"`
	// Nonce is the initial nonce for the new api token.
	Nonce int `json:"nonce"`
}

GenerateTokenResult represents the json returned from the token generation.

type Options

type Options struct {
	Key []byte
}

Options provide a way to pass arguments to the paseto middleware.

type TokenPayload added in v0.2.0

type TokenPayload struct {
	// LicenseID is the license this token is bound to.
	LicenseID uuid.UUID `json:"license_id"`
}

TokenPayload represents the encrypted json data included in each api token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL