Skip to content

rohitpjpti18/jvvt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

library for implementation of jwt in go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages