jwt

package module
v0.0.0-...-95b891f Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: MIT Imports: 3 Imported by: 3

README

jwt

Wrapper for https://github.com/dgrijalva/jwt-go to simplify Generation and validation of JWTs

Documentation

Overview

token package imnplements common methods for handling tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	errors.AuthErrCheck
	// contains filtered or unexported fields
}

JWT Handler handles JWT tokens with the help of the github.com/dgrijalva/jwt-go library. Call NewHandler() to get the correct instance of this struct.

func NewHandler

func NewHandler(hs256key []byte) (*Handler, error)

NewHandler constructs a Handler struct for handling JWT tokens.

func (*Handler) Generate

func (g *Handler) Generate(claims jwt.Claims) (string, error)

Generate generates a JWT token based on provided claims using jwt.SigningMethodHS256 to sign the token string. jwt.StandardClaims is a good starting point for a claims struct and can be extended to implement the jwt.Claims interface.

func (*Handler) Validate

func (g *Handler) Validate(token string, cs jwt.Claims) (*jwt.Token, error)

Validate validates a token that was generated using jwt.SigningMethodHS256 to sign the token string.

the error - err - returned will evaluate (*Handler).IsAuthError(err) to true if the token is invalid, otherwise any other error is returned if the parameters are invalid e.g. nil claims parameter.

The claims parameter should be a pointer to the struct to which the (valid) token is unmarshalled into.

The returned *jwt.Token provides standard information on the token.

Jump to

Keyboard shortcuts

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