| Crates.io | user_info_middleware |
| lib.rs | user_info_middleware |
| version | 0.2.0 |
| created_at | 2025-04-23 12:45:26.884891+00 |
| updated_at | 2025-04-23 12:45:26.884891+00 |
| description | Custom extractor for Rust Axum to extract the version from an HTTP header X-Endpoint-API-UserInfo. |
| homepage | |
| repository | https://github.com/nebetoxyz/rust-user-info-middleware--lib |
| max_upload_size | |
| id | 1645473 |
| size | 31,028 |
Custom extractor for Rust Axum to extract the request id from an HTTP header X-Endpoint-API-UserInfo.
Works ONLY with Rust Axum.
use axum::{routing::get, Router};
use user_info_middleware::ExtractUserInfo;
async fn handler(ExtractUserInfo(user_info): ExtractUserInfo) {
println!("User Info: {:?}", user_info);
}
let app = Router::<()>::new().route("/foo", get(handler));
If the extracted value is missing or is not a valid base 64 encoded JSON, it returns a 400 Bad Request with this message :
Invalid X-Endpoint-API-UserInfo : Not found : it's a requirement error ;Invalid X-Endpoint-API-UserInfo : Not a valid base 64 : it's a decoding error ;Invalid X-Endpoint-API-UserInfo : Not a valid JSON : it's a parsing error.curl -H "X-Endpoint-API-UserInfo: eyJpc3MiOiJteS1pc3N1ZXIiLCJzdWIiOiJteS1zdWJqZWN0IiwiYXVkIjoibXktYXVkaWVuY2UiLCJuYW1lIjoibXktbmFtZSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE2MjM5MDIyLCJuYmYiOjE1MTYyMzkwMjIsImp0aSI6Im15LXVuaXF1ZS1pZCJ9" http://api.nebeto.xyz/foo
curl -H "x-endpoint-api-userinfo: eyJpc3MiOiJteS1pc3N1ZXIiLCJzdWIiOiJteS1zdWJqZWN0IiwiYXVkIjoibXktYXVkaWVuY2UiLCJuYW1lIjoibXktbmFtZSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE2MjM5MDIyLCJuYmYiOjE1MTYyMzkwMjIsImp0aSI6Im15LXVuaXF1ZS1pZCJ9" http://api.nebeto.xyz/foo
curl -H "X-endPoint-Api-UserInfo: eyJpc3MiOiJteS1pc3N1ZXIiLCJzdWIiOiJteS1zdWJqZWN0IiwiYXVkIjoibXktYXVkaWVuY2UiLCJuYW1lIjoibXktbmFtZSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE2MjM5MDIyLCJuYmYiOjE1MTYyMzkwMjIsImp0aSI6Im15LXVuaXF1ZS1pZCJ9" http://api.nebeto.xyz/foo
Where eyJpc3MiOiJteS1pc3N1ZXIiLCJzdWIiOiJteS1zdWJqZWN0IiwiYXVkIjoibXktYXVkaWVuY2UiLCJuYW1lIjoibXktbmFtZSIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE2MjM5MDIyLCJuYmYiOjE1MTYyMzkwMjIsImp0aSI6Im15LXVuaXF1ZS1pZCJ9 is a base 64 encoded JSON :
{
"iss": "my-issuer",
"sub": "my-subject",
"aud": "my-audience",
"name": "my-name",
"iat": 1516239022,
"exp": 1516239022,
"nbf": 1516239022,
"jti": "my-unique-id"
}
Will give :
user_info["iss"] // "my-issuer"
user_info["sub"] // "my-subject"
user_info["aud"] // "my-audience"
user_info["name"] // "my-name"
user_info["iat"] // 1516239022
user_info["exp"] // 1516239022
user_info["nbf"] // 1516239022
user_info["jti"] // "my-unique-id"
For any question or feature suggestion, you can take a look and open, if necessary, a new discussion.
For any bug, you can take a look to our active issues and open, if necessary, a new issue.