Some checks failed
Native Verification / Build Docs (pull_request) Successful in 1m12s
Native Verification / Build App-Service Native (pull_request) Successful in 1m27s
Native Verification / Build Daemon Native (pull_request) Successful in 42s
Lint and Test Charts / lint-test (pull_request_target) Failing after 19s
Lint and Test Charts / test-version (pull_request_target) Successful in 0s
Lint and Test Charts / push-image (pull_request_target) Failing after 15s
Lint and Test Charts / upload-cli (pull_request_target) Failing after 1m15s
Lint and Test Charts / upload-daemon (pull_request_target) Failing after 1m12s
Lint and Test Charts / push-deps (pull_request_target) Has been skipped
Lint and Test Charts / push-deps-arm64 (pull_request_target) Has been skipped
Lint and Test Charts / push-image-arm64 (pull_request_target) Has been cancelled
Lint and Test Charts / upload-package (pull_request_target) Has been cancelled
Lint and Test Charts / install-test (pull_request_target) Has been cancelled
79 lines
1.2 KiB
Markdown
79 lines
1.2 KiB
Markdown
# `jwt` <!-- omit in toc -->
|
|
|
|
# Table of Contents
|
|
|
|
- [Table of Contents](#table-of-contents)
|
|
- [Usage](#usage)
|
|
- [Signing](#signing)
|
|
- [Verifying](#verifying)
|
|
- [Directory Structure](#directory-structure)
|
|
- [Rationale](#rationale)
|
|
|
|
|
|
# Usage
|
|
|
|
## Signing
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/beclab/beOS Pro/cli/pkg/web5/didjwk"
|
|
"github.com/beclab/beOS Pro/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
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/beclab/beOS Pro/cli/pkg/web5/dids"
|
|
"github.com/beclab/beOS Pro/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`. |