Skip to content

Commit

Permalink
[PLATFORM-535]: [jwks_client] Update README (#10)
Browse files Browse the repository at this point in the history
* Update documentation

* Add changelog

* Fix typo
  • Loading branch information
cottinisimone authored Jun 29, 2022
1 parent e7d487e commit a05dda9
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 9 deletions.
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- README code example updated with the latest changes.

## [0.3.0] - 2022-04-01

### Added

- Added new builder pattern struct `JwksClientBuilder`.
- Added `JwksClient::builder` function to create a new `JwksClientBuilder`.
- Added custom in-memory cache with entries TTL.

### Removed

- Removed `JwksClient::new` function.

## [0.2.0] - 2022-03-14

### Added

- Added `timeout` (default set to 10 seconds) and `connect_timeout` (default set to 20 seconds) functions. These values
are used in `reqwest::Client` to avoid never-ending http requests.
- Added new library usage [example](./examples/get_jwks.rs).
- Added library usage documentation.

### Changed

- Changed cache TTL duration set from 1 minute to 1 day.

## [0.1.0] - 2021-10-28

### Added

- First release 🎉

[Unreleased]: https://github.com/primait/jwks_client/compare/0.3.0...HEAD
[0.3.0]: https://github.com/primait/jwks_client/compare/0.2.0...0.3.0
[0.2.0]: https://github.com/primait/jwks_client/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/primait/jwks_client/releases/tag/0.1.0
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Add to your `Cargo.toml`
```toml
# Cargo.toml
[dependencies]
jwks_client_rs = "0.1.1"
jwks_client_rs = "0.3.0"
```

## Code example
Expand All @@ -27,8 +27,10 @@ let timeout: std::time::Duration = todo!();
let source: WebSource = WebSource::builder()
.with_timeout(timeout)
.with_connect_timeout(timeout)
.build(url);
let client: JwksClient = JwksClient::new(source);
.build(url);

let client: JwksClient<WebSource> = JwksClient::builder()
.build(source);

// Store your client in your application context or whatever
// ..
Expand Down Expand Up @@ -58,7 +60,9 @@ let result: Result<Claims, JwksClientError> = client.decode::<Claims>(token, aud

## Example

To run the example:
- Export the `KID` env variable (take if from your tenant well known jwks)
- Export the `BASE_AUTH0_URL` (something like `http://{your-tenant}.eu.auth0.com`)
- Run in shell `cargo run --bin get_jwks`
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`
7 changes: 5 additions & 2 deletions examples/get_jwks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ use jwks_client_rs::{JsonWebKey, JwksClient, JwksClientError};
#[tokio::main]
async fn main() {
// This value must be set as one of your tenant key id (in the json: "keys"[0]."kid")
// export KID={YOUR-KID}
// $ export KID={YOUR-KID}
let kid: String = std::env::var("KID").unwrap();
// This should be something like
// export AUTH0_BASE_URL=https://{YOUR-TENANT}.eu.auth0.com
// $ export AUTH0_BASE_URL=https://{YOUR-TENANT}.eu.auth0.com
// or running localauth0
// $ docker run -d -p 3000:3000 public.ecr.aws/prima/localauth0:0.3.0
// $ export AUTH0_BASE_URL=http://localhost:3000
let url_string: String = std::env::var("AUTH0_BASE_URL").unwrap();

let url: Url = Url::from_str(url_string.as_str()).unwrap();
Expand Down

0 comments on commit a05dda9

Please sign in to comment.