Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autodoc updates #1213

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions docs/01-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,9 @@ func ExampleJWT_ParseWithKeyProvider_UseToken() {
// load different keys.

// Setup
origIssuer := "me"
tok, err := jwt.NewBuilder().
Issuer("me").
Issuer(origIssuer).
Build()
if err != nil {
fmt.Printf("failed to build token: %s\n", err)
Expand Down Expand Up @@ -557,12 +558,16 @@ func ExampleJWT_ParseWithKeyProvider_UseToken() {
}

_, err = jws.Verify(signed, jws.WithKeyProvider(jws.KeyProviderFunc(func(_ context.Context, sink jws.KeySink, sig *jws.Signature, msg *jws.Message) error {
switch parsed.Issuer() {
iss, ok := parsed.Issuer()
if !ok {
return fmt.Errorf("no issuer found")
}
switch iss {
case "me":
sink.Key(alg, symmetricKey)
return nil
default:
return fmt.Errorf("unknown issuer %q", parsed.Issuer())
return fmt.Errorf("unknown issuer %q", iss)
}
})))

Expand All @@ -571,7 +576,7 @@ func ExampleJWT_ParseWithKeyProvider_UseToken() {
return
}

if parsed.Issuer() != tok.Issuer() {
if iss, ok := parsed.Issuer(); !ok || iss != origIssuer {
fmt.Printf("issuers do not match\n")
return
}
Expand Down Expand Up @@ -858,7 +863,11 @@ import (

func ExampleJWT_ValidateValidator() {
validator := jwt.ValidatorFunc(func(_ context.Context, t jwt.Token) jwt.ValidationError {
if t.IssuedAt().Month() != 8 {
iat, ok := t.IssuedAt()
if !ok {
return jwt.NewValidationError(errors.New(`token does not have "iat" claim`))
}
if iat.Month() != 8 {
return jwt.NewValidationError(errors.New(`tokens are only valid if issued during August!`))
}
return nil
Expand Down