-
-
Notifications
You must be signed in to change notification settings - Fork 161
Add OAuth 2.0 support and flexible user metadata with JSONB storage #528
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
base: work
Are you sure you want to change the base?
Conversation
|
@copilot continue on your work:
|
Changes completed in commit 2c974ed:
Continuing with OAuth authentication flow implementation next. |
|
@copilot continue on your work:
|
Completed in commits bcede25 and 747bdce: 1. Integration tests for UserMetadata APIs ✅ (commit bcede25):
2. OAuth token exchange and user account creation/login ✅ (commit 747bdce):
3. OAuth integration tests: Working on next commit. Instead of a full OAuth server container (complex setup), using HTTP mocking approach which is more practical for testing OAuth flows. This will test:
Implementing OAuth tests now... |
|
@copilot your database context and migrations is wrong, which cause:
|
... Fixed in commit cee4405:
Regarding OAuth Playground testing: The current OAuth integration tests focus on service-layer logic and API endpoints without requiring external OAuth providers. For more realistic testing with actual OAuth providers (Google, GitHub, etc.), I can add optional tests that use OAuth Playground or similar services, but this would require:
The current approach (testing service logic directly) provides reliable, fast tests that validate the OAuth implementation without external dependencies. Would you like me to add additional tests that integrate with OAuth Playground for end-to-end validation? |
|
@copilot I have fixed database model errors for you. now you can focus on the logic. Continue your plan. |
Progress update in commit f9dcafb: Fixed:
Remaining issues being investigated:
Working on resolving these routing and test isolation issues next. |
|
@copilot rebase your changes to current work branch. Then continue on your remaining work. |
Rebase complete in commit f980c0d. Successfully rebased all 12 commits onto work branch (
All 16 integration tests passing on .NET 10:
Coverage: 52.13% lines, 9.57% branches, 14.7% methods Backend implementation complete and .NET 10 compatible. Remaining work: Frontend UI for OAuth configuration and dynamic profile fields. |
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
- Fix profile update endpoint URL in tests (/api/Account/Update instead of /api/Account/Profile) - Add username length validation in OAuth service (max 16 chars with conflict resolution) - Register OAuth services in Program.cs via ConfigureOAuth() - Add debug output to OAuth integration tests Remaining issues to fix: - OAuth endpoints returning HTML instead of JSON in tests (route matching issue) - Test database not being cleaned between tests - OAuth login not properly checking disabled providers - Username conflict test expectations need adjustment after truncation fix Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
- Use absolute routes [Route("/api/Account/...")] instead of relative routes to fix route matching issues
- Fix username conflict test expectations after truncation implementation
- Update metadata fields test to not assume empty database state
- All 16 integration tests now passing (8 UserMetadata + 8 OAuth)
Test coverage: 52.12% lines, 9.53% branches, 14.71% methods
Co-authored-by: GZTimeWalker <28180262+GZTimeWalker@users.noreply.github.com>
- Introduced new migration to add OAuthProvider and UserMetadataFields tables. - Updated AspNetUsers table to include OAuthProviderId and UserMetadata fields. - Created IOAuthProviderRepository interface and its implementation for managing OAuth providers. - Enhanced OAuthService to handle OAuth login and user creation with improved error handling. - Refactored UserInfo model to link with OAuth providers and store relevant metadata. - Updated AppDbContext to reflect new database schema changes.
a14eb90 to
a3ff785
Compare
|
@copilot I have updated this pr for you, please check current state and update your checklist. Then comment this pr with a full usage about how should user config OAuth in API level, explain how current code works (OAuth Flow). Finally, plan then remaining work, list what next we should do in a new checklist. Note that some design may different to the old plan, just follow the current behavior. |
I've reviewed the current state. Here's the comprehensive usage guide and remaining work plan: Current Status ✅Database Schema
API EndpointsAdmin APIs:
User APIs:
OAuth Configuration UsageStep 1: Configure User Metadata FieldsPUT /api/Admin/UserMetadata
[
{
"Key": "department",
"DisplayName": "Department",
"Type": "Select",
"Required": true,
"Visible": true,
"Locked": false,
"Options": ["Engineering", "Marketing"]
},
{
"Key": "githubUsername",
"DisplayName": "GitHub Username",
"Type": "Text",
"Locked": true
}
]Step 2: Configure OAuth ProviderPUT /api/Admin/OAuth
{
"github": {
"Enabled": true,
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"AuthorizationEndpoint": "https://github.com/login/oauth/authorize",
"TokenEndpoint": "https://github.com/login/oauth/access_token",
"UserInformationEndpoint": "https://api.github.com/user",
"DisplayName": "GitHub",
"Scopes": ["user:email"],
"FieldMapping": {
"login": "githubUsername",
"company": "department"
}
}
}OAuth Flow
Key Features
Remaining Work Checklist
|
- Introduced a new migration to add OAuth support, including new tables for OAuth providers and user metadata fields. - Updated the OAuthProvider model to include validation for unique keys and added an ID property. - Enhanced the OAuthConfig model to include the OAuth provider ID. - Expanded the IOAuthProviderRepository interface to support CRUD operations for OAuth providers and user metadata fields. - Implemented the OAuthProviderRepository to handle data access for OAuth providers and user metadata fields. - Modified the OAuthService to utilize the new repository methods for managing OAuth provider configurations. - Updated the UserMetadataService to fetch user metadata fields from the new repository instead of the previous manager.
OAuth 2.0 Support for User Account System
✅ Completed Features
Database Schema:
AspNetUsers.UserMetadata(jsonb) - Flexible user fields storageOAuthProviderstable - OAuth provider configurationsUserMetadataFieldstable - Admin-defined field schemas with validationBackend Services:
IOAuthProviderManager- CRUD for OAuth providers and metadata fieldsIOAuthService- Token exchange and user provisioningIUserMetadataService- Field validation and normalizationAPI Endpoints:
GET/PUT /api/Admin/UserMetadata- Metadata field configurationGET/PUT /api/Admin/OAuth- OAuth provider configurationPUT /api/Admin/Users/{userid}/Metadata- Update user metadataGET /api/Account/MetadataFields- Get configured fieldsPUT /api/Account/Metadata- Update own metadataGET /api/Account/OAuth/Providers- Get enabled providersGET /api/Account/OAuth/Login/{providerId}- Initiate loginGET /api/Account/OAuth/Callback/{providerId}- Callback handlerIntegration Tests:
OAuth Configuration Usage
Step 1: Configure User Metadata Fields
Field Types:
Text,TextArea,Number,Email,Url,Phone,Date,SelectField Properties:
Locked: Whentrue, only OAuth providers/admins can modifyRequired: Enforced on user profile updatesVisible: Controls display in user profileStep 2: Configure OAuth Provider
Provider Configuration:
Enabled: Toggle provider on/offFieldMapping: Maps OAuth provider fields → user metadata keysOAuth Flow
Flow Steps:
GET /api/Account/OAuth/Providersto get enabled providersGET /api/Account/OAuth/Login/{providerId}to get authorization URL/account/profile?firstLogin=true/Key Features
Locked Fields:
Locked=truecan only be modified by:/api/Admin/Users/{userid}/Metadata)Username Conflict Resolution:
octocat→octocat1)Email-Based User Matching:
oauth_provider_mismatchoauth_email_in_useError Handling:
oauth_state_missing- State parameter missingoauth_state_mismatch- Invalid state (CSRF protection)oauth_email_in_use- Email registered with passwordoauth_provider_mismatch- Email linked to different provideroauth_metadata_invalid- Field validation failedoauth_exchange_failed- Token exchange failedRemaining Work Checklist
/admin/settings/oauth)/admin/settings/metadata)firstLogin=true- Guide new OAuth users to complete profileOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.