OAuth Adapter for Rust Web Frameworks
A universal OAuth 2.0 adapter for Rust web frameworks, providing a single configuration model and framework-specific glue so you can expose compliant token endpoints without duplicating logic.
Status: This crate is still in active development. The API described below represents the intended shape of the crate and may change before the first stable release.
Highlights
- Framework agnostic support for Axum, Warp, Actix-web, and Rocket
- Shared
OAuthConfigbuilder for consistent client credentials and token settings - Pluggable token store interface for Redis, SQL, or in-memory implementations
- Opinionated defaults with escape hatches for custom validation and token generation
Notice
⚠️ This crate is in early development. For production use, consider oauth2 as a mature alternative solution.
Installation
Add the crate to your Cargo.toml, enabling the integration you need:
[]
= { = "0.1.0", = false, = ["axum"] }
Available feature flags: axum, warp, actix, rocket. Combine them if you support multiple frameworks in the same binary.
Configuration At A Glance
Create an OAuthConfig once and share it across the adapters you enable:
use OAuthConfig;
let config = builder
.client_id
.client_secret
.issuer
.access_token_ttl
.refresh_token_ttl
.enable_refresh_tokens
.build
.expect;
The builder validates required fields and returns a Result<OAuthConfig, ConfigError>. Keep the resulting value in an Arc if you need to clone it between routes or filters.
Custom Token Storage
To persist tokens outside the default in-memory store, implement TokenStore and attach it to the configuration:
use ;
;
let config = builder
.client_id
.client_secret
.token_store
.build
.expect;
Framework Quick Starts
Each framework-specific integration exposes a thin wrapper that turns an OAuthConfig into the appropriate route handler.
Axum
use Arc;
use ;
use OAuthHandler;
use OAuthConfig;
async
Warp
use Arc;
use oauth_filter;
use OAuthConfig;
use Filter;
async
Actix-web
use Arc;
use ;
use configure_oauth;
use OAuthConfig;
async
Rocket
use Arc;
use oauth_routes;
use OAuthConfig;
use launch;
Supported OAuth 2.0 Grants
The adapter aims to cover the following grant types out of the box:
- Client Credentials
- Authorization Code (with PKCE support)
- Refresh Token
Additional flows (Device Code, Resource Owner Password) are planned once the core API stabilizes.
Token Endpoint Contract
All integrations expose a standardized token endpoint that accepts JSON requests:
Successful responses return RFC 6749-compliant JSON:
Contributing
We welcome pull requests and issues that help shape the API.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit (
git commit -m "feat: add amazing feature") - Push (
git push origin feature/amazing-feature) - Open a Pull Request
License
Distributed under the MIT License. See the LICENSE file for details.
Acknowledgements
- Inspired by the need for a unified OAuth solution across Rust web frameworks
- Built with ❤️ for the Rust community