jsonwebtoken

package module
v0.0.0-...-8ca5a73 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 5 Imported by: 0

README

JWT Helper Functions

Golang package of helper functions for encoding, signing, decoding and verifying JSON web tokens.

Built on top of github.com/dgrijalva/jwt-go with a smaller and simpler API.

If you have any suggestions, problems or bug reports please create an issue and I'll do my best to accommodate you. In addition simply starring the repo would show your support for the project and be very much appreciated!

Install
go get -u github.com/montanaflynn/jsonwebtoken
Example Usage

Examples programs using the package for creating and verifying JSON web tokens with HMAC, RSA and ECDSA algorithms and programs for generating a secure HMAC key or RSA and ECDSA public and private key .pem files:

algorithm encoding decoding generating keys
HMAC encode hmac jwt decode hmac jwt generate hmac key
RSA encode rsa jwt decode rsa jwt generate rsa keys
ECDSA encode ecdsa jwt decode ecdsa jwt generate ecdsa keys
Documentation

View the entire package documentation online at godoc.org or offline with godoc .

func EncodeHMAC(claims jwt.Claims, key []byte) (string, error) {...}
func DecodeHMAC(tokenString string, key []byte) (jwt.MapClaims, error) {...}

func EncodeRSA(claims jwt.Claims, key *rsa.PrivateKey) (string, error) {...}
func DecodeRSA(tokenString string, key *rsa.PublicKey) (jwt.MapClaims, error) {...}
func EncodeRSAFromPemFile(claims jwt.Claims, file string) (string, error) {...}
func DecodeRSAFromPemFile(tokenString string, file string) (jwt.MapClaims, error) {...}

func EncodeECDSA(claims jwt.Claims, key *ecdsa.PrivateKey) (string, error) {...}
func DecodeECDSA(tokenString string, key *ecdsa.PublicKey) (jwt.MapClaims, error) {...}
func EncodeECDSAFromPemFile(claims jwt.Claims, file string) (string, error) {...}
func DecodeECDSAFromPemFile(tokenString string, file string) (jwt.MapClaims, error) {...}

var ErrTokenCouldNotBeParsed       = errors.New("token could not be parsed")
var ErrTokenIsNotJSONWebToken      = errors.New("token is not a json web token")
var ErrTokenIsNotValid             = errors.New("token is not valid")
var ErrTokenIsNotActiveYet         = errors.New("token is not active yet")
var ErrTokenIsExpired              = errors.New("token is expired")
var ErrTokenClaimsCannotBeAsserted = errors.New("token claims cannot be asserted")

Documentation

Overview

Package jsonwebtoken is a set of helper functions for encoding, signing, decoding and verifying JSON web tokens built on top of https://github.com/dgrijalva/jwt-go with a smaller and simpler API.

Install latest version with:

go get -u github.com/montanaflynn/jsonwebtoken

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTokenCouldNotBeParsed is returned when a token could not be parsed
	ErrTokenCouldNotBeParsed = errors.New("token could not be parsed")

	// ErrTokenIsNotJSONWebToken is returned when a token is not a json web token
	ErrTokenIsNotJSONWebToken = errors.New("token is not a json web token")

	// ErrTokenIsNotValid is returned when a token is not valid
	ErrTokenIsNotValid = errors.New("token is not valid")

	// ErrTokenIsNotActiveYet is returned when a token is not active yet
	ErrTokenIsNotActiveYet = errors.New("token is not active yet")

	// ErrTokenIsExpired is returned when a token is expired
	ErrTokenIsExpired = errors.New("token is expired")

	// ErrTokenClaimsCannotBeAsserted is returned when token claims cannot be asserted
	ErrTokenClaimsCannotBeAsserted = errors.New("token claims cannot be asserted")
)

Functions

func DecodeECDSA

func DecodeECDSA(tokenString string, key *ecdsa.PublicKey) (jwt.MapClaims, error)

DecodeECDSA decodes and verifies a json web token using an ECDSA public key and returns a map of the claims held inside the token

func DecodeECDSAFromPemFile

func DecodeECDSAFromPemFile(tokenString string, file string) (jwt.MapClaims, error)

DecodeECDSAFromPemFile decodes and verifies a json web token using an ECDSA public key pem container formatted file path and returns a map of the claims held inside the token

func DecodeHMAC

func DecodeHMAC(tokenString string, key []byte) (jwt.MapClaims, error)

DecodeHMAC decodes and verifies a json web token using an HMAC secret key and returns a map of the claims held inside the token.

func DecodeRSA

func DecodeRSA(tokenString string, key *rsa.PublicKey) (jwt.MapClaims, error)

DecodeRSA decodes and verifies a json web token using an RSA public key and returns a map of the claims held inside the token.

func DecodeRSAFromPemFile

func DecodeRSAFromPemFile(tokenString string, filePath string) (jwt.MapClaims, error)

DecodeRSAFromPemFile decodes and verifies a json web token using an RSA public key pem container formatted file path and returns a map of the claims held inside the token.

func EncodeECDSA

func EncodeECDSA(claims jwt.Claims, key *ecdsa.PrivateKey) (string, error)

EncodeECDSA encodes and signs a json web token using the claims that the json web token should include and an an ECDSA private key.

func EncodeECDSAFromPemFile

func EncodeECDSAFromPemFile(claims jwt.Claims, file string) (string, error)

EncodeECDSAFromPemFile encodes and signs a json web token using the claims that the json web token should include and an ECDSA private key pem container formatted file.

func EncodeHMAC

func EncodeHMAC(claims jwt.Claims, key []byte) (string, error)

EncodeHMAC encodes and signs a json web token using the claims that the json web token should include and an HMAC secret key.

func EncodeRSA

func EncodeRSA(claims jwt.Claims, key *rsa.PrivateKey) (string, error)

EncodeRSA encodes and signs a json web token using the claims that the json web token should include and an an RSA private key.

func EncodeRSAFromPemFile

func EncodeRSAFromPemFile(claims jwt.Claims, filePath string) (string, error)

EncodeRSAFromPemFile encodes and signs a json web token using the claims that the json web token should include and an RSA private key pem container formatted file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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