auth0-integration
Auth0 client library for Rust — handles M2M token retrieval, JWT validation, and user management via the Auth0 Management API.
Installation
Add the crate to your Cargo.toml:
[]
= "0.2.1"
= { = "1", = ["full"] }
Configuration
The library reads Auth0 credentials from environment variables:
| Variable | Description |
|---|---|
AUTH0_DOMAIN |
Auth0 tenant domain (e.g. your-tenant.us.auth0.com) |
AUTH0_CLIENT_ID |
M2M application client ID |
AUTH0_CLIENT_SECRET |
M2M application client secret |
AUTH0_AUDIENCE |
API identifier registered in Auth0 |
use Auth0Config;
let config = from_env.expect;
Usage
Obtaining an M2M access token
Use Auth0ClientToken to run the Client Credentials flow. The response contains an AccessToken with the raw JWT string and a pre-decoded payload.
use ;
async
Calling the Auth0 Management API
Pass the AccessToken to Auth0Client to interact with the Management API.
use ;
use UpdateUserRequest;
async
Validating a JWT (RS256)
AccessToken::validate verifies the token signature, issuer, and audience against Auth0's JWKS endpoint.
use ;
async
Checking permissions (scopes)
use AccessToken;
let token = new.unwrap;
let claims = &token.decoded_access_token;
// Single permission
let can_read = claims.validate_permissions;
// Multiple — all must be present to return true
let can_manage = claims.validate_permissions;
Decoding a token payload (without verification)
use AccessToken;
let token = new.unwrap;
println!;
Key types
| Type | Module | Description |
|---|---|---|
Auth0Config |
auth0_integration |
Auth0 credentials loaded from env |
AppError |
auth0_integration |
Unified error type |
Auth0ClientToken |
auth0_integration::services |
Fetches M2M access tokens |
Auth0Client |
auth0_integration::services |
Auth0 Management API client |
AccessToken |
auth0_integration::models |
JWT with decoded payload |
AccessTokenResponse |
auth0_integration::models |
Full token endpoint response |
DecodedAccessToken |
auth0_integration::models |
Typed JWT claims (sub, iss, exp, etc.) |
Auth0User |
auth0_integration::models |
Auth0 user object |
UpdateUserRequest |
auth0_integration::models |
Payload for PATCH /api/v2/users/{id} |
CreateUserRequest |
auth0_integration::models |
Payload for POST /api/v2/users |
Docker
# Development (hot reload)
# View logs
License
MIT