Crates.io | azure_jwt_async |
lib.rs | azure_jwt_async |
version | 0.3.2 |
source | src |
created_at | 2023-12-21 15:18:31.99098 |
updated_at | 2023-12-21 20:57:04.113864 |
description | A simple JWT validator for Microsoft Azure tokens that is async capable. |
homepage | |
repository | https://github.com/0xNeffarion/azure-jwt-async |
max_upload_size | |
id | 1077048 |
size | 54,353 |
This library will fetch public keys from Microsoft and use those keys to validate the authenticity of a token you provide. It defaults to validating and mapping Azure Id tokens for you out of the box.
Azures public keys are fetched by sending request for them through the open-connect api. The default is to expire the stored keys after
24 hours and fetch new ones since that correspond with the normal key rotation scheme. There is also a default retry fallback
where a kid
that doesn't match any of our current public keys wil trigger one refresh of the keys (limited to once an hour),
just in case the set default is badly synced with the rotation of the public keys or Microsoft decides to rotate the keys
immediately for some reason. Both of these settings can be configured.
let client_id = "my client id from Azure";
let mut az_auth = AzureAuth::new(client_id).await.unwrap();
let decoded = az_auth.validate_token(TEST_TOKEN).await?;
When you create a new AzureAuth
instance in its default configuration it will trigger two calls
to Microsoft endpoints (one to get the open connect metadata to get the current jwks_uri and one to
fetch the jwk sets). You should create these objects with care and prefer using a reference to one
instance. If you're using it on a webserver you should avoid creating a new instance on every connection
and rather instantiate one on server start and use a mutex or channels to do validation. Once the keys
are loaded the operations should be very fast.
This library validates six things:
The validation will Error
on a failed validation providing more granularity for library users to find out why the token
was rejected.
You'll need:
You will need a private client_id created by Azure for your application to be able to verify that the token is created for your application (and not anyone with a valid Azure token can log in). This is the ID this library needs from you to authenticate that the token vas issued for your application.
You get a verified token parsed for you in return.
You still must take care of:
custom_validation
method.For more information, see this article: https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens