Tesseral for Axum
Tesseral’s Axum SDK lets you add authentication to your Rust Axum backend.
Getting Started
Add the Tesseral Axum SDK to your Cargo.toml:
Then, in the file where you create your Axum router, apply the require_auth
middleware:
Replace publishable_key_...
with your project’s Publishable Key. You can find
it in the API Keys
Settings of the
Tesseral Console.
Once you’ve added require_auth
, all HTTP requests to your server will be
authenticated. Inauthentic requests will receive a 401 Unauthorized
error
before they reach your route handlers.
Accessing details about the authenticated request
The Tesseral middleware adds an Auth
object to the request extensions. You can
extract this object in your handlers by adding it as a parameter:
Getting the current Organization
To access the Organization the request is for, use auth.organization_id()
:
This is the most common identifier you’ll use in a B2B SaaS application.
Getting the request’s authenticated credentials
If you need to forward along the request’s credentials, use auth.credentials()
:
Do not log or expose this value. You usually don’t need to use this unless you’re building internal service-to-service calls.
Getting details about the current User
To access extra details about the authenticated User, use auth.access_token_claims()
:
If the request is from an API Key, then
auth.access_token_claims()
is None
.
We recommend that you mostly use auth.organization_id()
in the vast majority
of your code; that is almost always the correct piece of information for most
B2B SaaS code should pay attention to. For more details, see B2B
Multitenancy.