Skip to content

Generating HMAC based token is so easy with simpletoken.

License

Notifications You must be signed in to change notification settings

ahmdrz/simpletoken

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Token !

Generating HMAC based token is so easy with simpletoken..

Installation

$ go get -u github.com/ahmdrz/simpletoken

Examples

package main

import (
	"fmt"
	"time"

	"github.com/ahmdrz/simpletoken"
)

type Payload struct {
	Username  string
	CreatedAt time.Time
}

func main() {
	simpleToken, err := simpletoken.New("md5", []byte("long-long-secret-key"))
	if err != nil {
		panic(err)
	}

	myPayload := Payload{
		Username:  "ahmdrz",
		CreatedAt: time.Now(),
	}
	token, err := simpleToken.Generate(myPayload)
	if err != nil {
		panic(err)
	}

	fmt.Printf("token is %s\n", token)

	output := Payload{}
	err = simpleToken.ParseString(token.String(), &output)
	if err != nil {
		panic(err)
	}

	fmt.Printf("payload is %v\n", output)
}

Find expirableToken example in example directory.

About

Generating HMAC based token is so easy with simpletoken.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages