Skip to content

ktaka-ccmp/oauth2-passkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1,502 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

logo

oauth2-passkey

๐Ÿ” Passwordless authentication for Rust web apps - No passwords, no 2FA implementation, better security.

Crates.io Crates.io Docs.rs License: MIT OR Apache-2.0

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.

๐ŸŽฎ Live Demo

passkey-demo.ccmp.jp

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:

demo-oauth2-passkey-register

Sign in with Passkey:

demo-passkey-login

โœจ What You Get

  • ๐Ÿ”‘ 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

๐Ÿš€ 5-Minute Setup

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.

๐Ÿ—๏ธ How It Works

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:

  1. First-time users can register with Google OAuth2 OR create a Passkey
  2. Existing users can add additional login methods to their account
  3. Authentication works with any linked method (OAuth2 or Passkey)
  4. Admin users (first user auto-promoted) can manage other accounts

๐Ÿ“ฑ Try the Demos

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:3001

๐Ÿ“ฆ Repository Structure

This repository contains:

๐Ÿ”ง Configuration

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=memory

OAuth2 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.

๐Ÿ“„ License

Licensed under either of:

at your option.

๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

About

Authentication library for Rust web applications with OAuth2/OIDC and WebAuthn/Passkey support.

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE-APACHE
MIT
LICENSE-MIT

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors