/jvvt

library for implementation of jwt in go

Primary LanguageGoGNU General Public License v3.0GPL-3.0

jvvt

library for implementation of json web tokens in go.

Getting started

Import the jvvt package in your code JvvtObj acts as a container for handling jwt tokens

Create a new JvvtObj

    secretKey := "someLargeSeceretKey" // ! IMPORTANT keep this key secret , 
    jvvtObj := jvvt.NewJvvtObj(secretKey)

claims is a struct type which acts as a payload for jwt token

type Claims struct {
	Issuer       string                 `json:"iss,omitempty"`
	Subject      string                 `json:"sub,omitempty"`
	Audience     string                 `json:"aud,omitempty"`
	Expiration   int64                  `json:"exp,omitempty"`
	NotBefore    int64                  `json:"nbf,omitempty"`
	IssuedAt     int64                  `json:"iat,omitempty"`
	OtherDetails map[string]interface{} `json:"other,omitempty"`
	JWTID        string                 `json:"jti,omitempty"`
}

creating a new claim object

myclaims := jvvt.NewClaims()
myclaims.Issuer = "dumbledore"
myclaims.Subject = "entry.to.hogwarts"
myclaims.IssuedAt = time.Now().Unix()                   // IssuedAt takes unix time only 
myclaims.Expiration = time.Now().AddDate(0,0,2).Unix()  // Expiration date of token 

generating a new token

token := jvvt.GenerateToken(claims)

verifying the token

isValid, err := jvvt.Verify(token)

getting claims from the raw token (Reading the token information)

claims, err := jvvt.GetClaims(token)