How ktaka-ccmp/oauth2-passkey works
• Frontend/Client Layer: Represent the demo applications (demo-integration, demo-oauth2, demo-passkey) that provide UI pages and interactions using templates (Jinja2-style, with .j2 files) alongside related javascript static files.
• Authentication Coordination Layer: Highlight the core library (oauth2_passkey) which consolidates several modules:
• OAuth2 Module: Covers configuration, storage, and processing for OAuth2 authentication, including integration (like Google).
• Passkey Module: Handles passkey credential registration, authentication flows (attestation, assertions), and related origin validations.
• Session & UserDB Modules: Manage session boundaries, context token verification, and user database interactions. Group components such as libsession, libstorage, and userdb (which manage state and persistence).
• Storage & Database Layer: Include separate representations for the different data stores:
• SQL Databases (PostgreSQL, SQLite) and their associated Docker Compose configurations.
• Redis for caching (with a dedicated cache store implementation).
• Clear_db_cache.sh and monitor_db.sh as auxiliary maintenance scripts.
• Configuration & Deployment: Mark the configuration files (Cargo.toml for each project, dot.env.example) and deployment scripts (docker-compose.yaml files present under db directories) that ensure consistency of the environment and schema checks during database initialization.
Relationships and Interactions
• How the web server (oauth2_passkey_axum) invokes the coordination layer (oauth2_passkey) which, in turn, interacts with the storage/data store modules.
• Session boundaries and middleware validation flows, for example, the validation logic that differentiates between “create new user” versus “add to existing user.”
• Interaction flows for external OAuth2 providers and signals (e.g., signalAllAcceptedCredentials, signalCurrentUserDetails, and signalUnknownCredential) that communicate between the relying party and authenticators.
Architectural Patterns and Design Principles
• Modular and Layered Design: The project is split into multiple coordinated libraries (modules for OAuth2, passkey, session, storage) that get consolidated into one cohesive authentication ecosystem (often referred to as libauth in the README).
• Separation of Concerns: Clearly separate the frontend (UI and demo pages), backend authentication logic (coordinators and modules), and persistence layers.
• Middleware-Based Protection: There’s an emphasis on middleware (e.g., is_authorized middleware) ensuring that different pages and endpoints enforce correct session/user context.
Technologies and Frameworks
• Rust as the programming language with Cargo for dependency management.
• Axum framework for building the HTTP server and routing middleware.
• Docker Compose for containerizing PostgreSQL, Redis, and SQLite configurations.
• WebAuthn/Passkey and OAuth2 fundamentals as implemented in separate modules, along with integration of self-signed TLS certificates for demo environments.