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 ¶
ExtractAccountID return AccountID from context.Context.
func Generate ¶
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