How apratham/electron-oauth-app works
Project type and purpose
• This is a cross-platform desktop application built with Electron, serving as a reference implementation for OAuth 2.0 (Google and Microsoft) in a desktop environment. It provides login, logout, and splash flows all within a single packaged app.
File structure
• Top-level entrypoints:
• main.js – Electron “main” process (app lifecycle, BrowserWindow creation, deep-link handling)
• index.js – Electron “renderer” entrypoint for the primary UI (loaded in index.html)
• Renderer assets (HTML/CSS/JS sets for each screen):
• splash.html/css/js
• login.html/css/js
• logout.html/css/js
• index.html/css/js (post-login UI)
• Shared assets & configuration:
• config/.versionrc, scripts/increment-version.js – version bump tooling
• secrets-example.js – placeholder for OAuth client IDs/secrets (renamed to secrets.js at runtime)
• Packaging & build:
• package.json – dependencies (Electron, electron-builder, Ionic, etc.) and scripts (start, build)
• electron-builder config in package.json (targeting Windows, macOS, Linux)
• CI/CD: GitHub Actions workflow badge in README indicates automated releases via .github/workflows/release.yml
Review README insights
• Purpose: showcase Google and Microsoft OAuth flows in an Electron context
• Tech stack: Node.js LTS, Electron ^30.1.1, electron-builder ^24.13.3, Ionic components for UI consistency
• External dependencies: Google OAuth 2.0 endpoints, Microsoft identity platform (Graph API for basic profile scopes)
Main components
a. Electron Main Process
• App initialization & window management
• Deep-link / custom URI schema handler (“myapp://auth”) for OAuth callbacks
• IPC channel to/from Renderer processes
• Version bump script integration (calls increment-version.js)
b. Electron Renderer Processes (UI Layer)
• Splash Screen
• Login Screen – triggers OAuth popup via Main Process
• Primary App UI (index.html/js) – displays user info after successful login
• Logout Screen – clears session and returns to login
c. Configuration & Secrets
• secrets.js (client IDs, secrets, redirect URIs) loaded by Main Process
d. External Services
• Google OAuth 2.0 Authorization Server
• Microsoft Identity Platform (Graph API endpoints)
e. Build & Release Pipeline
• electron-builder (packaging to .exe, .dmg, .AppImage)
• GitHub Actions for automated releases
Relationships & data flows
• App Startup: Main → launches Splash Renderer
• Renderer → Main via IPC: “ready” event → Main opens Login Renderer
• Login Renderer → Main: “start-oauth” with provider choice → Main opens external OAuth window
• OAuth Window → External Provider (HTTPS request/redirect flow) → Redirect to custom URI → Main intercepts callback
• Main → extracts tokens → IPC send “oauth-success” + token payload → Primary Renderer
• Primary Renderer → calls Main for any further interactions (refresh, logout)
• Logout Renderer → Main clears token state → returns to Login Renderer
Architectural patterns & design principles
• Electron’s multi‐process architecture (separation of concerns between Main and Renderer)
• Event‐driven communications via IPC channels
• Externalizing secrets/config to a dedicated file for environment-specific overrides
• Build‐time versioning with a script and configuration file