simplejwt

package module
v0.0.0-...-afb7969 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2017 License: MIT Imports: 7 Imported by: 0

README

simplejwt

A simple JSON Web Tokens package in Go

Description

You can easly add JWT authentication with the help of this package to your golang web application.

Examples

Generate New Token

To generate a new token, use NewToken():

f := make(map[string]interface{})

f["iat"] = time.Now().UTC().Unix()
f["exp"] = time.Now().UTC().Add(time.Hour).Unix()
f["nbf"] = time.Now().UTC().Add(-time.Minute).Unix()

t, err := simplejwt.NewToken(&f, []byte("very-secret-password"))
Parse and Verify Token

To parse and verify a token, use ParseToken():

_, ok, err := ParseToken(t, []byte("very-secret-password"))

In this example, the value of ok should be true if the token is valid.

Remarks

Only HS256 hash algorithm is supported at the moment.

Installation

go get -u github.com/akosmarton/simplejwt

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewToken

func NewToken(fields map[string]interface{}, key []byte) (string, error)

NewToken generates a new JWT token. You should fill the claim fields.

func ParseToken

func ParseToken(token string, key []byte) (map[string]interface{}, bool, error)

ParseToken parses a JWT token and validates (only) the signature

func VerifyExp

func VerifyExp(exp interface{}, now int64) bool

VerifyExp verifies exp field

func VerifyFields

func VerifyFields(fields map[string]interface{}) bool

VerifyFields verifies all fields

func VerifyIat

func VerifyIat(iat interface{}, now int64) bool

VerifyIat verifies iat field

func VerifyNbf

func VerifyNbf(nbf interface{}, now int64) bool

VerifyNbf verifies nbf field

Types

This section is empty.

Jump to

Keyboard shortcuts

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