Skip to content

feat: add OAuth/social login providers plugin (Phase 1)#742

Merged
lane711 merged 7 commits intomainfrom
fix/issue-737
Apr 5, 2026
Merged

feat: add OAuth/social login providers plugin (Phase 1)#742
lane711 merged 7 commits intomainfrom
fix/issue-737

Conversation

@lane711
Copy link
Copy Markdown
Collaborator

@lane711 lane711 commented Apr 3, 2026

Summary

Adds OAuth2/OIDC social login support as a core plugin, implementing Phase 1 of #737. Users can sign in via GitHub or Google using the standard OAuth2 authorization code flow, with automatic account linking by email.

Changes

  • New plugin: oauth-providers built with the PluginBuilder SDK
  • OAuth2 authorization code flow with cryptographic CSRF state protection
  • Two built-in providers: GitHub and Google (provider-agnostic design makes adding more trivial)
  • Account linking: OAuth profiles are auto-linked to existing accounts by email match
  • New user creation: Creates accounts from OAuth profile data when no matching email exists
  • Database migration (034): oauth_accounts table with proper indexes and foreign key to users
  • Routes:
    • GET /auth/oauth/:provider — Redirect to provider authorization
    • GET /auth/oauth/:provider/callback — Handle OAuth callback
    • POST /auth/oauth/link — Link OAuth to existing account
    • POST /auth/oauth/unlink — Unlink OAuth provider
    • GET /auth/oauth/accounts — List linked accounts
  • Zero new dependencies — uses native fetch for all OAuth HTTP calls
  • Cloudflare Workers compatible — no Node.js-specific APIs
  • Plugin registered in core plugins index, bootstrap service, and app route mounting

Files Changed

  • packages/core/src/plugins/core-plugins/oauth-providers/index.ts (new)
  • packages/core/src/plugins/core-plugins/oauth-providers/oauth-service.ts (new)
  • packages/core/src/plugins/core-plugins/oauth-providers/manifest.json (new)
  • packages/core/src/db/migrations/0010_oauth_accounts.sql (new)
  • packages/core/src/db/migrations-bundle.ts (migration 034 added)
  • packages/core/src/app.ts (route registration)
  • packages/core/src/index.ts (exports)
  • packages/core/src/plugins/core-plugins/index.ts (exports + CORE_PLUGIN_IDS)
  • packages/core/src/services/plugin-bootstrap.ts (core plugin entry)

Testing

  • All 55 existing test files pass (1399 tests pass, 0 failures)
  • Lint passes (warnings only, consistent with existing codebase)
  • TypeScript type-check passes with zero errors

Configuration

After enabling the plugin, configure provider credentials in the admin plugin settings page:

{
  "providers": {
    "github": { "clientId": "...", "clientSecret": "...", "enabled": true },
    "google": { "clientId": "...", "clientSecret": "...", "enabled": true }
  }
}

Future Work (Phase 2+)

  • Discord, Microsoft/Azure AD, Generic OIDC providers
  • TOTP/2FA integration
  • Account linking management UI
  • JWT claims enrichment from OAuth profiles

Fixes #737

Implements the core OAuth2 authorization code flow as a SonicJS plugin,
enabling social login via GitHub and Google providers.

Changes:
- New oauth-providers plugin with PluginBuilder SDK pattern
- OAuth2 authorization code flow with CSRF state protection
- GitHub and Google as built-in providers (provider-agnostic design)
- Account linking: auto-links OAuth to existing email accounts
- New user creation from OAuth profile data
- oauth_accounts database migration (table + indexes)
- Registered in core plugins, bootstrap service, and app routes
- No new dependencies — uses native fetch for all OAuth HTTP calls
- Cloudflare Workers compatible

Routes added:
  GET  /auth/oauth/:provider          — Redirect to provider
  GET  /auth/oauth/:provider/callback — Handle callback
  POST /auth/oauth/link               — Link OAuth to account
  POST /auth/oauth/unlink             — Unlink OAuth provider
  GET  /auth/oauth/accounts           — List linked accounts

Fixes #737
lane711 and others added 5 commits April 4, 2026 16:56
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…P site name

New docs pages:
- QR Code Generator plugin
- Redirect Management plugin
- Forms as Collections

Updated docs:
- Authentication: RBAC enforcement details, rate limiting, CSRF
- Field Types: collapsible fields, objectLayout
- Core Plugins: added new plugins
- API Reference: auto-discovery mention

Bug fix:
- OTP plugin email preview now reads site name from General Settings
  (was using wrong DB query, always showed 'SonicJS')

🤖 Generated with [Claude Code](https://claude.com/claude-code)
…tory function (#741)

Script tags inserted via innerHTML are not executed by the browser. After
loading version history HTML into the modal container, we now manually
re-create script elements so the browser executes them, making
closeVersionHistory and other functions available to onclick handlers.

Fixes #666
The OTP plugin settings page has a Logo URL field but it was never
passed to the email template or the admin preview. Now:
- logoUrl is passed from plugin settings to the email template data
- Admin preview shows the logo above 'Your Login Code' header
- Added logoUrl to OTPSettings interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Change the Plugin type import in oauth-providers/index.ts from
'@sonicjs-cms/core' (circular package import) to relative '../../types'.

Change index.ts to import OAuth exports directly from the oauth-providers
subdirectory instead of from core-plugins/index.ts, which was pulling in
all core plugins and their unresolvable @sonicjs-cms/core imports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lane711 lane711 merged commit 319f6b9 into main Apr 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: OAuth/Social Login Providers Plugin

1 participant