token

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2018 License: GPL-3.0, GPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Overview

Package token provide support for generating and validating JWT tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAccountID

func ExtractAccountID(r *http.Request) bson.ObjectId

ExtractAccountID return AccountID from context.Context.

func Generate

func Generate(id bson.ObjectId, key []byte) (string, error)

Generate generate JWT token for account, signed by key. Used claims: "id" -> account.ID (bson.ObjectId), "exp" -> exp time (int64).

func NewValidationMiddleware

func NewValidationMiddleware(key []byte) middleware.Middleware

NewValidationMiddleware create middleware which validate access to next http.Handler. Returned middleware call next.Serve.Http(w, r), if token from response is correct. Otherwise WriteHeader http.StatusUnauthorized and write proper message to w. Token is taken from HTTP header: "X-Auth-Token". Token claims are passed by context.Context.

Types

type ContextKeyType

type ContextKeyType int

ContextKeyType is type of keys used in context.Context map TODO move somewhere else

const ContextIDKey ContextKeyType = 0

ContextIDKey is key for "id" in context.Context map

Jump to

Keyboard shortcuts

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