JSON Web Token Interface built on top of golang-jwt
Create a private and public key pair in root directory
e.g. creating RSA key pair via
openssl
openssl genrsa -out rsa_prv.key 2048 && openssl rsa -RSAPublicKey_out -in rsa_prv.key -out rsa_pub.key
go get it (pun intended 😸)
go get github.com/JuneKimDev/token
package main
import (
"log"
"github.com/JuneKimDev/token"
)
func init(){
// For token issuer
if err := token.InitPrvKey("rsa_prv.key"); err != nil {
log.Fatal(err)
}
// For token verifier
if err := token.InitPubKey("rsa_prv.key"); err != nil {
log.Fatal(err)
}
}
func issue() (string, int64, error){
subIP := "127.0.0.1"
subID := "clientId"
sub := token.GetSubject(subIP, subID)
aud := "test.aud"
expIn := "1h"
return token.Create(sub, aud, expIn)
}
func main() {
// tokenstring from http request
aud := "test.aud"
subject, err = token.Verify(tokenstring, aud)
if err != nil {
log.Println(err)
}
userIP, userID := token.ParseSubject(subject)
// Do something with it
}