An OAuth 2.1 authorization server for Rust apps, built for MCP servers and for any API that lets third-party apps act on a person's behalf.
It implements the MCP authorization spec, so Claude, ChatGPT, Codex, Cursor, VS Code and other MCP clients can connect to your server with a sign-in and a consent page. Your app keeps its own users, sign-in and database.
DocSpring maintains it for its own products, starting with VisualCI.
- The authorization code flow, with PKCE S256 only.
- Client ID metadata documents (the MCP spec's preferred way for a client to identify itself) and dynamic client registration (RFC 7591).
issin every authorization response (RFC 9207).- Tokens bound to the resource they were issued for (RFC 8707).
- Authorization server metadata (RFC 8414) and protected resource metadata (RFC 9728), and the
WWW-Authenticatechallenge that points MCP clients at them. - Refresh tokens that rotate on every use. A refresh token used twice revokes the whole connection, and so does an authorization code used twice, including tokens a racing request wrote (the storage serialises writes into a connection with its revocation). A request that fails a check spends nothing, so the client can retry.
- Token revocation (RFC 7009) and introspection (RFC 7662).
- Every code, token and client secret is stored as a SHA-256, with prefixes that secret scanners can match.
- A consent verdict for each app: verified (a known client, by its metadata document's domain), unreviewed, or a lookalike of a known app's name (with Unicode confusables folded). Your app renders the page.
- A fetcher for metadata documents that refuses private addresses, follows no redirects and caps the size.
It leaves to your app: who the person is (your sign-in and sign-up), the markup of the consent page, rate limits, and where things are stored.
| Crate | What it is |
|---|---|
oauth-provider |
The core: rules, flows and the Storage trait. No web framework, no database. |
oauth-provider-axum |
The endpoints on axum routes, the consent flow, and a bearer-token middleware. |
oauth-provider-postgres |
Storage on PostgreSQL (sqlx). |
oauth-provider-sqlite |
Storage on SQLite (sqlx), for a single machine. |
oauth-provider-storage-tests |
The conformance suite every Storage must pass. |
oauth-provider-mcp |
The MCP clients to recognise, a safe metadata document fetcher, and an MCP Config. |
oauth-provider-verify |
Verification for a resource server in another process, by introspection. |
use std::sync::Arc;
use oauth_provider::{Provider, ResourceVerifier, Verify};
use oauth_provider_postgres::PostgresStorage;
let storage = PostgresStorage::new(pool);
storage.migrate().await?;
let config = oauth_provider_mcp::mcp_config("https://mcp.example.com", "https://app.example.com/oauth/authorize")
.with_service_name("Example")
.with_prefixes(oauth_provider::Prefixes {
access: "exa_at_".into(),
refresh: "exa_rt_".into(),
client_secret: "exa_cs_".into(),
});
let provider = Arc::new(Provider::new(config, storage)?.with_documents(oauth_provider_mcp::HttpDocuments::new()?));
// On mcp.example.com: discovery, registration, token, revocation.
let oauth = oauth_provider_axum::endpoints(provider.clone());
// On app.example.com, where your sign-in session is: the consent page.
let consent = oauth_provider_axum::authorize(provider.clone(), Arc::new(MyPages::new()));
// Your MCP server, behind the bearer middleware.
let verifier: Arc<dyn Verify> = Arc::new(ResourceVerifier::new(provider.clone(), "https://mcp.example.com/mcp"));
let mcp = mcp_router.layer(axum::middleware::from_fn_with_state(verifier, oauth_provider_axum::require_bearer));MyPages implements AuthorizeApp: it says who's signed in, sends everyone else to sign in or sign up (and back),
renders the consent page from a ConsentPage, and reads the person's decision from the form. A handler behind the
middleware gets the grant with the Authorized extractor: the subject (your user id), the client and the scopes.
Someone with no account can arrive from an MCP client. AuthorizeApp::sign_in sends them to your sign-in page
with return_to set to the authorization request. Your sign-up creates their account and returns them there,
and the consent page continues the flow to the client. Mark the session as "signed up for this client", and
report it as Viewer::just_signed_up, so the consent page can say the account is ready.
Scopes are plain strings, and authorization is up to your app. Decision::Approve can narrow the scopes the client
asked for, or add your own (org:acme) when the person limits the connection to some of their data. A handler that
needs a scope calls grant.require(&["admin"]); oauth_provider_axum::refused turns the refusal into a 403 whose
challenge names the scopes, so an MCP client can ask the person for more.
A resource server in another process or on another machine verifies tokens with
oauth_provider_verify::Introspector. It implements the same Verify trait, so the same middleware works. Give each
resource server its own secret in the authorization server's config, with the resources it may ask about:
Config::with_introspection(&digest(secret), &["https://api.example.com/"]).
Implement oauth_provider::Storage for your own database, or use the PostgreSQL or SQLite crate. Run the conformance
suite from your implementation's tests:
#[tokio::test(flavor = "multi_thread")]
async fn conforms() {
oauth_provider_storage_tests::run(|| async { MyStorage::empty().await }).await;
}It checks the guarantees the server relies on, including that racing requests consume a code or refresh token exactly once.
This is 0.1. The API follows semantic versioning: until 1.0, a minor version (0.2) may break the API, and a patch version (0.1.1) won't. Every change is in the changelog.
Planned: JWT access tokens with a JWKS endpoint, for resource servers that verify without calling the authorization server.
The minimum supported Rust version is 1.94.
Please report vulnerabilities privately: see SECURITY.md.
Issues and pull requests are welcome: see CONTRIBUTING.md.
Apache-2.0. See LICENSE.