Olares/cli/pkg/web5/jwt
2025-06-12 14:23:19 +08:00
..
jwt.go daemon: change the module name of the olares-daemon (#1436) 2025-06-12 14:23:19 +08:00
jwt_test.go daemon: change the module name of the olares-daemon (#1436) 2025-06-12 14:23:19 +08:00
README.md cli: change the module name of the cli (#1431) 2025-06-11 23:06:24 +08:00

jwt

Table of Contents

Usage

Signing

package main

import (
	"fmt"
	"github.com/beclab/Olares/cli/pkg/web5/didjwk"
    "github.com/beclab/Olares/cli/pkg/web5/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/beclab/Olares/cli/pkg/web5/dids"
    "github.com/beclab/Olares/cli/pkg/web5/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.