-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Co-authored-by: GZTimeWalker <[email protected]>
Co-authored-by: GZTimeWalker <[email protected]>
|
@copilot continue on your work:
|
Co-authored-by: GZTimeWalker <[email protected]>
Changes completed in commit 2c974ed:
Continuing with OAuth authentication flow implementation next. |
Co-authored-by: GZTimeWalker <[email protected]>
|
@copilot continue on your work:
|
Co-authored-by: GZTimeWalker <[email protected]>
Co-authored-by: GZTimeWalker <[email protected]>
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... |
Co-authored-by: GZTimeWalker <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## work #528 +/- ##
==========================================
+ Coverage 58.32% 59.21% +0.89%
==========================================
Files 183 192 +9
Lines 9110 9648 +538
Branches 1118 1174 +56
==========================================
+ Hits 5313 5713 +400
- Misses 3384 3508 +124
- Partials 413 427 +14
🚀 New features to boost your workflow:
|
|
@copilot your database context and migrations is wrong, which cause:
|
Co-authored-by: GZTimeWalker <[email protected]>
... 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. |
- 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 <[email protected]>
Progress update in commit f9dcafb: Fixed:
Remaining issues being investigated:
Working on resolving these routing and test isolation issues next. |
- 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 <[email protected]>
Implements complete OAuth 2.0 provider infrastructure and admin-configurable user metadata fields with comprehensive integration tests. Addresses requirement for flexible user data collection (StdNumber, RealName, etc.) beyond fixed schema columns, with OAuth integration for external authentication.
Database Schema
AspNetUsers.UserMetadata(jsonb): Key-value storage for dynamic user fieldsOAuthProviders: Generic OAuth provider configurations (all providers treated equally)FieldMapping(jsonb): Maps OAuth provider fields to user metadata fieldsUserMetadataFields: Admin-defined field schemasUserMetadataFieldTypeenum: Text, TextArea, Number, Email, Url, Phone, Date, SelectAPI Endpoints
User Metadata (Admin) - Independent from OAuth:
GET /api/Admin/UserMetadata: Retrieve user metadata fields configurationPUT /api/Admin/UserMetadata: Update user metadata fields configurationOAuth Providers (Admin):
GET /api/Admin/OAuth: Retrieve OAuth providers configurationPUT /api/Admin/OAuth: Update OAuth providers configurationUser Endpoints:
GET /api/Account/MetadataFields: List available metadata fields for profile completionPUT /api/Account/Update: Update profile with dynamic metadataGET /api/Account/OAuth/Providers: Get available OAuth providers for loginGET /api/Account/OAuth/Login/{provider}: Initiate OAuth login flowGET /api/Account/OAuth/Callback/{provider}: OAuth callback handler (internal use)Service Layer
IOAuthProviderManager:IOAuthService:ExchangeCodeForUserInfoAsync: Exchanges authorization code for access token and fetches user info from OAuth providerGetOrCreateUserFromOAuthAsync: Creates new user or updates existing user with OAuth dataOAuth Flow
Complete OAuth 2.0 implementation with all providers treated as generic:
GET /api/Account/OAuth/Login/{provider}FieldMappingConfiguration Examples
Admin configures OAuth provider (GitHub):
{ "github": { "Enabled": true, "ClientId": "...", "ClientSecret": "...", "AuthorizationEndpoint": "https://github.com/login/oauth/authorize", "TokenEndpoint": "https://github.com/login/oauth/access_token", "UserInformationEndpoint": "https://api.github.com/user", "Scopes": ["user:email"], "FieldMapping": { "login": "username", "email": "email", "name": "realName", "company": "organization" } } }Admin configures user metadata field:
{ "Key": "department", "DisplayName": "Department", "Type": "Select", "Required": true, "Visible": true, "Options": ["Engineering", "Marketing", "Sales"] }User profile update includes dynamic metadata:
{ "Metadata": { "department": "Engineering", "studentId": "2024001" } }Migration
AddUserMetadataAndOAuthSupport: Creates tables and adds UserMetadata column with{}default.Design Decisions
EmailConfirmed=trueas providers verify emailsIntegration Tests
Added comprehensive integration tests (16 total, 100% passing):
UserMetadata Tests (8 tests):
OAuth Tests (8 tests):
Tests use direct service testing and API integration validation with real PostgreSQL database via Testcontainers. All tests passing with 52.12% line coverage.
Status
Notes
RealNameandStdNumbercolumns retained for backward compatibilityConfigureOAuth()extension methodOriginal 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.