Skip to content

Commit

Permalink
Merge pull request #58 from Sovietaced/accessToken
Browse files Browse the repository at this point in the history
Update README for background fetching
  • Loading branch information
Sovietaced authored Jul 4, 2024
2 parents 7ff3dd2 + 427dfa8 commit cdad72f
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ includes support for telemetry (ie. OpenTelemetry), minimizing verification late

## Examples

### Access Token Validation
### Token Validation

```go
package main

import (
"context"
verifier "github.com/sovietaced/okta-jwt-verifier"
Expand All @@ -29,6 +30,39 @@ func main() {
accessToken := "..."
token, err = v.VerifyAccessToken(ctx, accessToken)
}
```

### Background Fetching Optimization
By default, the okta JWT verifier will lazily fetch OIDC metadata and JSON Web Key sets. When the first call to verify a
token is made a couple of HTTP requests will be made inline and block your call to verify the token. You can configure
the verifier to fetch OIDC metadata and JSON Web Key sets asynchronously in the background to optimize token
verification duration.

```go
package main

import (
"context"
kf "github.com/sovietaced/okta-jwt-verifier/keyfunc/okta"
md "github.com/sovietaced/okta-jwt-verifier/metadata/okta"
verifier "github.com/sovietaced/okta-jwt-verifier"
)

func main() {
ctx := context.Background()
issuer := "https://test.okta.com"

mpProvider, err := md.NewMetadataProvider(issuer, md.WithFetchStrategy(md.Background))
kfProvider, err := kf.NewKeyfuncProvider(mpProvider, kf.WithFetchStrategy(kf.Background))
v, err := verifier.NewVerifier(issuer, verifier.WithKeyfuncProvider(kfProvider))

idToken := "..."
token, err := v.VerifyIdToken(ctx, idToken)

accessToken := "..."
token, err = v.VerifyAccessToken(ctx, accessToken)
}
```



0 comments on commit cdad72f

Please sign in to comment.