Skip to content

Commit

Permalink
autodoc updates (#740)
Browse files Browse the repository at this point in the history
Co-authored-by: lestrrat <lestrrat@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and lestrrat committed May 16, 2022
1 parent f9f2e00 commit 6b1f5fe
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions docs/01-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,21 +941,34 @@ func ExampleJWT_SerializeJWS() {
return
}

key, err := jwk.FromRaw([]byte(`abracadavra`))
rawKey := []byte(`abracadavra`)
jwkKey, err := jwk.FromRaw(rawKey)
if err != nil {
fmt.Printf("failed to create symmetric key: %s\n", err)
return
}

serialized, err := jwt.Sign(tok, jwt.WithKey(jwa.HS256, key))
if err != nil {
fmt.Printf("failed to sign token: %s\n", err)
return
// This example shows you two ways to passing keys to
// jwt.Sign()
//
// * The first key is the "raw" key.
// * The second one is a jwk.Key that represents the raw key.
//
// If this were using RSA/ECDSA keys, you would be using
// *rsa.PrivateKey/*ecdsa.PrivateKey as the raw key.
for _, key := range []interface{}{rawKey, jwkKey} {
serialized, err := jwt.Sign(tok, jwt.WithKey(jwa.HS256, key))
if err != nil {
fmt.Printf("failed to sign token: %s\n", err)
return
}

fmt.Printf("%s\n", serialized)
}

fmt.Printf("%s\n", serialized)
// OUTPUT:
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjIzMzQzMTIwMCwiaXNzIjoiZ2l0aHViLmNvbS9sZXN0cnJhdC1nby9qd3gifQ.rTlpyVnHFWosNud7seqlsvhM8UoXUIAKfdWHySFO5Ro
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjIzMzQzMTIwMCwiaXNzIjoiZ2l0aHViLmNvbS9sZXN0cnJhdC1nby9qd3gifQ.rTlpyVnHFWosNud7seqlsvhM8UoXUIAKfdWHySFO5Ro
}
```
source: [examples/jwt_serialize_jws_example_test.go](https://github.com/lestrrat-go/jwx/blob/v2/examples/jwt_serialize_jws_example_test.go)
Expand Down

0 comments on commit 6b1f5fe

Please sign in to comment.