OAuth Federation Architecture

Overview

Federation is the pattern where users can authenticate with multiple OAuth providers (GitHub, Discord, Google, Roblox, Ethereum), but all logins link to a single Foundation Passport.

This solves the problem of identity fragmentation: instead of one GitHub account, one Discord account, and one Google account being three separate users, they all represent the same person with one persistent identity.


The Problem (Without Federation)

User logs in with GitHub (github_user_123)
  → Creates account A in aethex.dev

Same user logs in with Discord (discord_user_456)
  → Creates account B in aethex.dev (doesn't know this is the same person)

Same user logs in with Roblox (roblox_user_789)
  → Creates account C in aethex.dev (still doesn't know)

Result: 3 separate accounts, 3 separate identities, 3 separate dashboards

The Solution (With Federation)


Architecture

Database Schema

Federation Flow

First Login with Provider X

Second Login with Different Provider Y (Same Person)

Case A: Direct Provider Match

Case B: Email Match (Account Recovery)


API Implementation

Foundation Helper: federateOAuthUser()

Logic:

  1. Look up provider_identities table

    • If found → return linked Passport user_id

    • If not found → create new Passport + provider link

  2. Always returns same user_id for same provider

  3. Enables multiple providers to link to same Passport

OAuth Callback Updates

Each OAuth callback (GitHub, Discord, Google, Roblox, Ethereum) now:


Login Flow (Updated)

Before (No Federation)

After (Federation)


User Experience

First Time User (Multi-Provider)

Existing User (Adding Providers)


Security Considerations

Provider ID Collision (Prevented)

→ Prevents provider ID from linking to multiple Passports

Account Takeover (Prevented)

→ User can't link same provider twice → User can't have duplicate providers

→ For auto-linking on email match, require email verification → Prevent account takeover via unverified email addresses


Supported Providers

  • GitHub - OAuth 2.0

  • Google - OAuth 2.0

  • Discord - OAuth 2.0

  • Roblox - Custom OAuth

  • Ethereum - Web3 (sign message)

All providers federate to Foundation Passports via federateOAuthUser().


Migration Path (Existing Users)

If you had existing users with separate GitHub/Discord/Google accounts:


Benefits

One Identity - Users have one Passport regardless of provider ✅ Flexible Login - Users can switch between providers seamlessly ✅ Data Consistency - No duplicate user records ✅ Security - Prevents account fragmentation ✅ Future Growth - Easy to add new OAuth providers ✅ Account Recovery - Email-based recovery across providers


References

  • code/api/_oauth-federation.ts - Federation helper functions

  • code/supabase/migrations/20250115_oauth_federation.sql - Database schema

  • OAuth endpoints: /api/github/oauth/callback, /api/discord/oauth/callback, etc.

Last updated