https://github.com/primait/jwks_client
Prima JWKS-sync client implementation for Auth0
https://github.com/primait/jwks_client
Last synced: 8 months ago
JSON representation
Prima JWKS-sync client implementation for Auth0
- Host: GitHub
- URL: https://github.com/primait/jwks_client
- Owner: primait
- Created: 2021-10-28T08:36:50.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-11-27T14:49:24.000Z (8 months ago)
- Last Synced: 2025-11-30T07:45:05.596Z (8 months ago)
- Language: Rust
- Homepage:
- Size: 102 KB
- Stars: 10
- Watchers: 44
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# JWKS Client
This lib is used to store Json Web Key Set from your authentication provider. It stores in an internal Cache fetched JWKS
and automatically refresh them after a given time.
## Installation
Add to your `Cargo.toml`
```toml
# Cargo.toml
[dependencies]
jwks_client_rs = "0.5.2"
```
## Code example
```rust
// Put in your application context or wherever this can live long enough
use jwks_client_rs::source::WebSource;
use jwks_client_rs::JwksClient;
// here you must join your `BASE_AUTH0_URL` env var with `.well-known/jwks.json` or whatever is the jwks url
let url: reqwest::Url = todo!();
let timeout: std::time::Duration = todo!();
// You can define a different source too using `JwksSource` trait
let source: WebSource = WebSource::builder()
.with_timeout(timeout)
.with_connect_timeout(timeout)
.build(url);
let client: JwksClient = JwksClient::builder()
.build(source);
// Store your client in your application context or whatever
// ..
// Get jwk by kid
use jwks_client_rs::{JsonWebKey, JwksClientError};
let kid: String = todo!();
let result: Result = app_context.jwks_client.get(kid).await;
```
It is possible to decode your token validating it has been signed by one of your authentication provider JWKS.
```rust
#[derive(serde::Deserialize)]
struct Claims {
aud: String,
}
let client: JwksClient = todo!();
// Here's the token. Remember to remove "Bearer " from your token in case it is present
let token: &str = todo!();
// The audience the token were released for.
let audience: &str = todo!();
let result: Result = client.decode::(token, audience).await;
```
## Example
A working example could be found in [examples](./examples) folder. To run the example:
- Export the `KID` env variable (take it from your tenant well known jwks)
- Export the `BASE_AUTH0_URL` (by running [localauth0](https://github.com/primait/localauth0) or using your
auth0 tenant; the url should be your localauth0 exposed port on `localhost` or something like
`https://{your-tenant}.eu.auth0.com`)
- Run in shell `cargo run --example get_jwks`