/jwt

JWT for Humans

Primary LanguageGoMIT LicenseMIT

jwt - human friendly json web token library

Build Status Coverage Status Go Report Card Documentation GitHub issues Release

import "github.com/contiamo/jwt"

Usage

type Claims

type Claims map[string]interface{}

Claims is a map of string->something containing the meta infos associated with a token

func CreateToken

func CreateToken(claims Claims, key interface{}) (string, error)

CreateToken takes some claims and a key (either private rsa, private ec or hmac key) and returns a signed json web token

func GetTokenFromRequest

func GetTokenFromRequest(r *http.Request) (string, string, error)

GetTokenFromRequest takes the first Authorization header and extracts the bearer json web token

func LoadPrivateKey

func LoadPrivateKey(keyFile string) (interface{}, error)

LoadPrivateKey loads a PEM encoded private key (either rsa or ec)

func LoadPublicKey

func LoadPublicKey(keyFile string) (interface{}, error)

LoadPublicKey loads a PEM encoded public key (either rsa or ec)

func ParsePrivateKey

func ParsePrivateKey(data []byte) (interface{}, error)

ParsePrivateKey parses a pem encoded private key (rsa or ecdsa based)

func ParsePublicKey

func ParsePublicKey(data []byte) (interface{}, error)

ParsePublicKey parses a pem encoded public key (rsa or ecdsa based)

func GetClaimsFromRequest

func GetClaimsFromRequest(r *http.Request, key interface{}) (string, Claims, error)

GetClaimsFromRequest extracts the token from a request, returning the claims

func GetClaimsFromRequestWithValidation

func GetClaimsFromRequestWithValidation(r *http.Request, key interface{}) (string, Claims, error)

GetClaimsFromRequestWithValidation extracts and validates the token from a request, returning the claims

func ValidateToken

func ValidateToken(tokenString string, key interface{}) (Claims, error)

ValidateToken checks the signature of the token with a given public key and returns the associated claims