https://github.com/rawnly/auth0-jwt
https://github.com/rawnly/auth0-jwt
auth0 auth0-rust jwt rust token
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/rawnly/auth0-jwt
- Owner: rawnly
- Created: 2022-12-19T18:16:03.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-18T13:24:39.000Z (about 2 years ago)
- Last Synced: 2025-04-12T13:09:18.746Z (about 1 year ago)
- Topics: auth0, auth0-rust, jwt, rust, token
- Language: Rust
- Homepage: https://crates.io/crates/auth0-jwt
- Size: 40 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Auth0 JWT
> Auth0 utility to check if the given JWT is valid.
## Usage
```rust
use auth0_jwt::get_claims;
#[tokio::async]
async fn main() {
let token = env!("JWT_TOKEN");
let claims = get_claims(&token).unwrap();
println!("Claims {}", claims);
}
```
## Features
- `claims` - Exports the `Claims` struct which is useful for deserialization.
- `axum` - Implements the `FromRequestParts` trait for `Claims` and provides a `Token(String)` extractor for convenience.
## Axum Example
Detailed example [here](./examples/axum-hello-world)
```rust
use auth0_jwt::claims::Claims;
use axum::{response::IntoResponse, routing::get, Json, Router};
use dotenv::dotenv;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
#[tokio::main]
async fn main() {
dotenv().ok();
// build our application with a route
let app = Router::new().route("/", get(handler));
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
println!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
#[derive(Serialize)]
struct ResponseBody {
message: &'static str,
}
#[derive(Deserialize, Serialize)]
struct ClaimsContent {
pub exp: usize,
pub iat: usize
}
async fn handler(Claims(claims): Claims) -> impl IntoResponse {
println!("{:?}", claims.exp);
Json(ResponseBody {
message: "hello world",
})
}
```