jwt

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 3 Imported by: 3

README

JWT toolkit

Signing and verifying JWT token with custom RSA key

  1. Generating RSA key: `
# Created Private key
ssh-keygen -t rsa -f key.pem -m pem 
or 
openssl genpkey -out private.txt -outform PEM -algorithm RSA -pkeyopt rsa_keygen_bits:4096
#  Created public key with:
openssl pkey -inform PEM -outform PEM -in private.txt -pubout -out public.txt
  1. Secure rsa.json with scy client (use one of the supported security store)
     scy -m=secure -s=public.txt -d=public.scy -t=raw -k=blowfish://default ## on prod, use secure store instead of local fs
     scy -m=secure -s=private.txt -d=private.scy -t=raw -k=blowfish://default ## on prod, use secure store instead of local fs
    
  2. To sign JWT Claim a) Creates jwt Claim in JSON format
   echo '{"user_id":123,"email":"dev@viantinc.com"}' > claims.json 

b) Sign claim

   scy -m=signJwt -s=claims.json -e=600 -r=private.scy -k=blowfish://default
  1. To verify JWT Claim scy -m=verifyJwt -s=token.json -r=public.scy -k=blowfish://default



Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Email         string      `json:"email,omitempty"`
	UserID        int         `json:"user_id,omitempty"`
	Username      string      `json:"username,omitempty"`
	FirstName     string      `json:"first_name,omitempty"`
	LastName      string      `json:"last_name,omitempty"`
	AccountName   string      `json:"account_name,omitempty"`
	AccountId     int         `json:"account_id,omitempty"`
	Scope         string      `json:"scope,omitempty"`
	Cognito       string      `json:"cognito,omitempty"`
	VerifiedEmail bool        `json:"verified_email,omitempty"`
	Data          interface{} `json:"dat,omitempty"`
	jwt.RegisteredClaims
}

Claims represents JWT claim

func NewClaim

func NewClaim(token *jwt.Token) (*Claims, error)

NewClaim returns jwt claim from token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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