Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created May 16, 2022 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/b025267932ae423bd1ef8208b8c14597 to your computer and use it in GitHub Desktop.
Save lestrrat/b025267932ae423bd1ef8208b8c14597 to your computer and use it in GitHub Desktop.
// https://github.com/lestrrat-go/jwx/blob/129e8b1d3bc86038ded5b41e8720b120194074f8/examples/jwt_builder_example_test.go
package examples_test
import (
"encoding/json"
"fmt"
"os"
"github.com/lestrrat-go/jwx/v2/jwt"
)
func ExampleJWT_Builder() {
tok, err := jwt.NewBuilder().
Claim(`claim1`, `value1`).
Claim(`claim2`, `value2`).
Issuer(`github.com/lestrrat-go/jwx`).
Audience([]string{`users`}).
Build()
if err != nil {
fmt.Printf("failed to build token: %s\n", err)
return
}
if err := json.NewEncoder(os.Stdout).Encode(tok); err != nil {
fmt.Printf("failed to encode to JSON: %s\n", err)
return
}
// OUTPUT:
// {"aud":["users"],"claim1":"value1","claim2":"value2","iss":"github.com/lestrrat-go/jwx"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment