Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 1.19 KB

README.md

File metadata and controls

79 lines (60 loc) · 1.19 KB

jwt

Table of Contents

Usage

Signing

package main

import (
	"fmt"
	"github.com/decentralized-identity/web5-go/didjwk"
    "github.com/decentralized-identity/web5-go/jwt"
)

func main() {	
	did, err := didjwk.Create()
	if err != nil {
		panic(err)
	}

	claims := jwt.Claims{
		Issuer: did.URI,
		Misc:   map[string]interface{}{"c_nonce": "abcd123"},
	}

	jwt, err := jwt.Sign(claims, did)
	if err != nil {
		panic(err)
	}
}

Verifying

package main

import (
	"fmt"
	"github.com/decentralized-identity/web5-go/dids"
    "github.com/decentralized-identity/web5-go/jwt"
)

func main() {
    someJWT := "SOME_JWT"
	ok, err := jwt.Verify(signedJWT)
	if err != nil {
		panic(err)
	}

    if (!ok) {
        fmt.Printf("dookie JWT")
    }
}

specifying a specific category of key to use relative to the did provided can be done in the same way shown with jws.Sign

Directory Structure

jwt
├── jwt.go
└── jwt_test.go

Rationale

same as jws.