sjwt

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

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

Go to latest
Published: Dec 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 1

README

simple-jwt

A very simple JWT implementation written in Go.

Install
$ go get -u github.com/OliverPohlak/simple-jwt
Usage
package main

import (
	"fmt"

	sjwt "github.com/OliverPohlak/simple-jwt"
)

var secret = "53cr3tk3y"

func main() {
	// Create new token
	jwt := sjwt.New()
	jwt.SetPayload("name", "mrsih")
	token, _ := jwt.Sign(secret)

	// Verify token
	jwt2, _ := sjwt.Parse(token)
	err := jwt2.Verify(token, secret)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	// Identify user
	name, ok := jwt2.Payload("name")
	if ok {
		fmt.Println(name)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *jwt

func Parse

func Parse(token string) (*jwt, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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