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.6.3"
= { = "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.
use ;
async
Calling the Auth0 Management API
Pass the raw token string to Auth0Client to interact with the Management API.
use ;
use UpdateUserRequest;
async
Validating a JWT (RS256)
TokenValidator verifies the token signature, issuer, and audience against Auth0's JWKS endpoint.
It caches the JWKS keys in memory and refreshes them automatically on a cache miss or validation failure.
Create one instance per application (e.g. wrap in Arc) and reuse it across requests.
use Arc;
use ;
async
Using with Axum state
use Arc;
use ;
use ;
async
Checking permissions (scopes)
use AccessToken;
let token = new;
// Single permission
let can_read = token.validate_permissions;
// Multiple — all must be present to return true
let can_manage = token.validate_permissions;
Decoding a token payload (without verification)
use AccessToken;
let token = new;
match token.decoded
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 |
TokenValidator |
auth0_integration |
Validates JWT strings against Auth0 JWKS with in-memory key cache |
AccessToken |
auth0_integration::models |
JWT wrapper with lazy 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 |
Role |
auth0_integration |
User role enum (Admin, SuperAdmin, Worker); parses from "admin" / "super_admin" / "worker" |
UpdateUserRequest |
auth0_integration::models |
Payload for PATCH /api/v2/users/{id} |
CreateUserRequest |
auth0_integration::models |
Payload for POST /api/v2/users |
License
MIT