-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Add oauth support #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces OAuth2 authentication and account linking functionality, starting with Discord as the first supported provider. The implementation includes comprehensive endpoints for user signup/signin via OAuth, account linking for existing users, and passwordless account creation.
Key Changes:
- OAuth Infrastructure: Added OAuth controllers, authentication schemes, and flow management with temporary cookie-based state handling
- Database Schema: Introduced
UserOAuthConnectiontable and made user passwords nullable to support OAuth-only accounts - Account Service Extensions: Enhanced account creation to support OAuth-only (passwordless) accounts with email verification logic
Reviewed Changes
Copilot reviewed 44 out of 45 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Common/OpenShockDb/UserOAuthConnection.cs | New entity for storing OAuth provider connections |
| Common/OpenShockDb/User.cs | Made PasswordHash nullable for OAuth-only accounts |
| API/Services/OAuthConnection/ | Service layer for managing OAuth connections |
| API/Controller/OAuth/ | OAuth flow endpoints (authorize, handoff, finalize) |
| API/Controller/Account/Authenticated/ | OAuth connection management for authenticated users |
| Common/Utils/AuthUtils.cs | Enhanced authentication utilities with OAuth support |
Files not reviewed (1)
- Common/Migrations/20250903235304_AddOAuthSupport.Designer.cs: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR introduces OAuth2 authentication and account linking into the API, starting with Discord as the first supported provider.
🔑 Key Additions
OAuth Controller & Endpoints
GET /oauth/providers– list supported providers.GET /oauth/{provider}/authorize– begin login-or-create flow.GET /oauth/{provider}/handoff– process provider callback, either sign in or continue flow.GET /oauth/{provider}/data– retrieve handoff data (email, display name, expiry).POST /oauth/{provider}/finalize– finalize flow: create a new account or link to an existing one.Account OAuth Connections
GET /account/connections– list linked connections.GET /account/connections/{provider}/link– initiate link flow.DELETE /account/connections/{provider}– unlink a provider.Database & Services
UserOAuthConnectionstable.OAuthConnectionServicefor managing external identities.AccountServicewith support for creating OAuth-only accounts (passwordless).Authentication & Config
AuthConstantswith flow types (login-or-create,link).⚙️ Step-by-Step Flow
Frontend requests login/signup with Discord
→ Calls
GET /oauth/discord/authorizeRedirect to Discord
→ User consents and Discord redirects back to
/oauth/discord/handoffHandoff decision
oauth/discord/create(new account) oroauth/discord/link(link existing account).Frontend fetches temporary identity data
→ Calls
GET /oauth/discord/datato display email/display name.Finalize flow
POST /oauth/discord/finalizecreate→ new OAuth-only account is created and linked.link→ external identity is attached to the logged-in account.OAuth connection persisted
→ Stored in
UserOAuthConnectionsand accessible under/account/connections.🚀 Impact