jwt

package
v0.0.0-...-760e1c2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MIT Imports: 2 Imported by: 0

README

jwt

The package jwt is used to create and parse JWT tokens.

import (
	"fmt"
	"time"

	"github.com/ricoberger/gocommon/jwt"

	jwtgo "github.com/dgrijalva/jwt-go"
)

func main() {
	token, err := jwt.Create(jwtgo.MapClaims{
		"exp":  time.Now().Add(time.Hour * 24 * 7).Unix(),
		"data": "hello world",
	}, "mysecret")
	if err != nil {
		return
	}

	claims, err := jwt.Parse(token, "mysecret")
	if err != nil {
		return
	}

	fmt.Println(claims)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrJwtValidationFailed is used if the validation of a jwt token fails.
	ErrJwtValidationFailed = errors.New("jwt validation failed")
	// ErrUnexpectedSigningMethod is used if the signing method of a provided jwt token is invalid.
	ErrUnexpectedSigningMethod = errors.New("unexpected signing method")
)

Functions

func Create

func Create(claims jwt.MapClaims, signingSecret string) (string, error)

Create creates, signs, and encodes a JWT token using the HMAC signing method.

func Parse

func Parse(tokenString, signingSecret string) (jwt.MapClaims, error)

Parse parses and validates a token using the HMAC signing method.

Types

This section is empty.

Jump to

Keyboard shortcuts

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