๐ Passwordless authentication for Rust web apps - No passwords, no 2FA implementation, better security.
Password authentication is fundamentally flawed - even strong, unique passwords are vulnerable to phishing, brute-force attacks, and server-side breaches. This library provides a better approach: users register with an OAuth2/OIDC provider (Google, plus presets for Auth0, Keycloak, Microsoft Entra ID, Zitadel, Okta, Authentik, LINE, Apple, or any standards-compliant OIDC IdP via generic slots), then add a Passkey for fast, phishing-resistant daily login. OAuth2 remains as a backup if the device is lost. After authentication, the library issues a secure session cookie to maintain login state.
No setup required. Sign in with Google, Auth0, Microsoft Entra ID, or LINE. Data is ephemeral (resets on server restart, sessions expire in 10 min).
Register with Google and add a Passkey:
Sign in with Passkey:
- ๐ Passkey - Phishing-resistant login with biometrics, inherently multi-factor (no 2FA needed)
- ๐ OAuth2 / OIDC - One-click registration and backup authentication. Google plus 8 preset providers (Auth0, Keycloak, Microsoft Entra ID, Zitadel, Okta, Authentik, LINE, Apple) and 8 generic slots for any standards-compliant OIDC IdP
- ๐ Account linking - Users can add multiple login methods to one account
- ๐ฆ Minimal setup - Works with SQLite out of the box, scales to PostgreSQL + Redis
1. Add to your Cargo.toml:
[dependencies]
oauth2-passkey-axum = "0.6"2. Set your environment variables:
ORIGIN='https://your-domain.com'
OAUTH2_GOOGLE_CLIENT_ID='your-google-client-id'
OAUTH2_GOOGLE_CLIENT_SECRET='your-google-secret'3. Add to your Axum app:
use axum::{Router, routing::get, response::IntoResponse};
use oauth2_passkey_axum::{AuthUser, oauth2_passkey_full_router};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
oauth2_passkey_axum::init().await?;
let app = Router::new()
.route("/", get(home))
.route("/protected", get(protected))
.merge(oauth2_passkey_full_router());
// Your app is now ready with login/logout at /o2p/*
Ok(())
}
async fn home() -> &'static str {
"Welcome! Visit /o2p/user/login to sign in"
}
async fn protected(user: AuthUser) -> impl IntoResponse {
format!("Hello, {}! ๐", user.account)
}That's it! Your users can now sign-in/register with Google or Passkeys.
Simple Architecture:
Your Web App
โ
oauth2-passkey-axum โ Handles login/logout routes
โ
oauth2-passkey โ Core session & auth logic
โ
Database + Cache โ SQLite/PostgreSQL + Memory/Redis
User Experience:
- First-time users can register with Google OAuth2 OR create a Passkey
- Existing users can add additional login methods to their account
- Authentication works with any linked method (OAuth2 or Passkey)
- Admin users (first user auto-promoted) can manage other accounts
See it in action before integrating:
| Demo | Description |
|---|---|
| demo-both | Complete OAuth2 + Passkey authentication |
| demo-oauth2 | OAuth2 only ("Sign in with Google") |
| demo-passkey | Passkey only (passwordless) |
| demo-custom-login | Custom login page implementation |
| demo-profile | User profile extension |
| demo-todo | App data linked to users |
| demo-cross-origin | Cross-origin authentication setup |
# Copy demo configuration
cp dot.env.simple demo-both/.env
# Run the demo (includes both OAuth2 and Passkeys)
cd demo-both && cargo run
# Open in your browser:
# Visit http://localhost:3001This repository contains:
oauth2_passkey/- Core authentication libraryoauth2_passkey_axum/- Axum web framework integrationdemo-*/- 7 demo applications (see table above)docs/- Documentation (mdBook format) | Read onlinedb/- Database configuration (Docker Compose)
Environment Variables (create a .env file):
ORIGIN='https://your-domain.com'
OAUTH2_GOOGLE_CLIENT_ID='your-google-client-id'
OAUTH2_GOOGLE_CLIENT_SECRET='your-google-secret'
# Database (SQLite by default; PostgreSQL or MySQL/MariaDB for production)
GENERIC_DATA_STORE_TYPE=sqlite
GENERIC_DATA_STORE_URL='sqlite:data/auth.db'
# Cache (Memory by default, Redis for production)
GENERIC_CACHE_STORE_TYPE=memoryOAuth2 Setup: Get Google credentials from the Google API Console and add redirect URI: https://your-domain.com/o2p/oauth2/google/authorized. For other providers (Auth0, Keycloak, Microsoft Entra ID, Zitadel, Okta, Authentik, LINE, Apple, or any OIDC IdP via generic slots) see the Provider Guides.
Licensed under either of:
at your option.
Contributions welcome! See CONTRIBUTING.md for guidelines.