diff --git a/docs/task-11-pre-register-console-client.md b/docs/task-11-pre-register-console-client.md new file mode 100644 index 0000000..d332b2f --- /dev/null +++ b/docs/task-11-pre-register-console-client.md @@ -0,0 +1,69 @@ +# Task 11: Pre-register Fengling.Console as OAuth Client + +## Task Description + +**Files:** +- Modify: `src/Fengling.AuthService/Data/SeedData.cs` + +## Implementation Steps + +### Step 1: Add Fengling.Console registration to SeedData + +Edit: `src/Fengling.AuthService/Data/SeedData.cs` + +Add after existing seed data: +```csharp +// Register Fengling.Console as OAuth client +var consoleClient = await context.OAuthApplications + .FirstOrDefaultAsync(c => c.ClientId == "fengling-console"); +if (consoleClient == null) +{ + consoleClient = new OAuthApplication + { + ClientId = "fengling-console", + ClientSecret = "console-secret-change-in-production", + DisplayName = "Fengling 运管中心", + RedirectUris = new[] { "http://console.fengling.local/auth/callback" }, + PostLogoutRedirectUris = new[] { "http://console.fengling.local/" }, + Scopes = new[] { "api", "offline_access" }, + GrantTypes = new[] { "authorization_code", "refresh_token" }, + ClientType = "confidential", + ConsentType = "implicit", + Status = "active", + CreatedAt = DateTime.UtcNow + }; + context.OAuthApplications.Add(consoleClient); + await context.SaveChangesAsync(); +} +``` + +### Step 2: Commit + +```bash +git add src/Fengling.AuthService/Data/SeedData.cs +git commit -m "feat(auth): pre-register Fengling.Console as OAuth client" +``` + +## Context + +This task pre-registers Fengling.Console as an OAuth client in the seed data. This allows the console to use OAuth2 authorization code flow for authentication. + +**OAuth Client Configuration:** +- ClientId: `fengling-console` +- Redirect URI: `http://console.fengling.local/auth/callback` +- Scopes: `api`, `offline_access` +- Grant Types: `authorization_code`, `refresh_token` + +## Verification + +- [ ] Fengling.Console client added to seed data +- [ ] Client configured with correct redirect URIs +- [ ] Client has required scopes and grant types +- [ ] Build succeeds +- [ ] Committed to git + +## Notes + +- Client secret should be changed in production +- Redirect URI matches Fengling.Console domain +- Client will be created on first application startup diff --git a/src/Fengling.AuthService/Data/SeedData.cs b/src/Fengling.AuthService/Data/SeedData.cs index 872e167..cd659a2 100644 --- a/src/Fengling.AuthService/Data/SeedData.cs +++ b/src/Fengling.AuthService/Data/SeedData.cs @@ -77,5 +77,27 @@ public static class SeedData await userManager.AddToRoleAsync(testUser, "User"); } } + + var consoleClient = await context.OAuthApplications + .FirstOrDefaultAsync(c => c.ClientId == "fengling-console"); + if (consoleClient == null) + { + consoleClient = new OAuthApplication + { + ClientId = "fengling-console", + ClientSecret = "console-secret-change-in-production", + DisplayName = "Fengling 运管中心", + RedirectUris = new[] { "http://console.fengling.local/auth/callback" }, + PostLogoutRedirectUris = new[] { "http://console.fengling.local/" }, + Scopes = new[] { "api", "offline_access" }, + GrantTypes = new[] { "authorization_code", "refresh_token" }, + ClientType = "confidential", + ConsentType = "implicit", + Status = "active", + CreatedAt = DateTime.UtcNow + }; + context.OAuthApplications.Add(consoleClient); + await context.SaveChangesAsync(); + } } } diff --git a/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.dll b/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.dll index 1a5071f..9f76a02 100644 Binary files a/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.dll and b/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.dll differ diff --git a/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.pdb b/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.pdb index 8edf5aa..2cbbe21 100644 Binary files a/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.pdb and b/src/Fengling.AuthService/bin/Debug/net10.0/Fengling.AuthService.pdb differ diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfo.cs b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfo.cs index b47ca8e..c8d95ba 100644 --- a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfo.cs +++ b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("Fengling.AuthService")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d3810f5d43139224571e9558a8f9d1caf253a2af")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5cdcba7e57f11cbe819ef947fe4f31dfa3f31ce5")] [assembly: System.Reflection.AssemblyProductAttribute("Fengling.AuthService")] [assembly: System.Reflection.AssemblyTitleAttribute("Fengling.AuthService")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfoInputs.cache b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfoInputs.cache index 147ce5a..e9c4cb4 100644 --- a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfoInputs.cache +++ b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.AssemblyInfoInputs.cache @@ -1 +1 @@ -6eb848986322eda4a24415ea7940bb6189775a7373c0cc69971ba237cf3fdeb1 +88557c3b57a3995d38feba9efb65b2d453135485aca705ead19cfd3379fa5af3 diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.csproj.CoreCompileInputs.cache b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.csproj.CoreCompileInputs.cache index 151e12e..56dccfc 100644 --- a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.csproj.CoreCompileInputs.cache +++ b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -246db42ea15f5b11045c9c9e1cfc0e315b80d78a560048b99d9119120a177411 +a442fae7d5599fed904d1202772e57ff3d3723e8af039346ca13fe6adc50709d diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.dll b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.dll index 1a5071f..9f76a02 100644 Binary files a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.dll and b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.dll differ diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.pdb b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.pdb index 8edf5aa..2cbbe21 100644 Binary files a/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.pdb and b/src/Fengling.AuthService/obj/Debug/net10.0/Fengling.AuthService.pdb differ diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/ref/Fengling.AuthService.dll b/src/Fengling.AuthService/obj/Debug/net10.0/ref/Fengling.AuthService.dll index 00770eb..d75cd12 100644 Binary files a/src/Fengling.AuthService/obj/Debug/net10.0/ref/Fengling.AuthService.dll and b/src/Fengling.AuthService/obj/Debug/net10.0/ref/Fengling.AuthService.dll differ diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/refint/Fengling.AuthService.dll b/src/Fengling.AuthService/obj/Debug/net10.0/refint/Fengling.AuthService.dll index 00770eb..d75cd12 100644 Binary files a/src/Fengling.AuthService/obj/Debug/net10.0/refint/Fengling.AuthService.dll and b/src/Fengling.AuthService/obj/Debug/net10.0/refint/Fengling.AuthService.dll differ diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/rjsmcshtml.dswa.cache.json b/src/Fengling.AuthService/obj/Debug/net10.0/rjsmcshtml.dswa.cache.json index 9c97f14..eba4df2 100644 --- a/src/Fengling.AuthService/obj/Debug/net10.0/rjsmcshtml.dswa.cache.json +++ b/src/Fengling.AuthService/obj/Debug/net10.0/rjsmcshtml.dswa.cache.json @@ -1 +1 @@ -{"GlobalPropertiesHash":"kj0YdTIP9epXJ4ydBR9yaRr5OemJ36+FlRmnBdiGrUE=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["nGadCmuBEG\u002BKUP6Powa57G4ZzOO6ibT7XQKZuYm3g44=","elQhyiEcBZcCHMIxyXyx47S4otwc/MEXjAYU/dca/hQ=","XrkTC/5D0wT4Vj8udAqp\u002B2DDPMQ5H3P4YZDu2X62NzI=","chR\u002BAL8taCFTQytCSiXtu6MS2y5z2GmMYAK8xprfbvA=","QUvWOS2l6Gf\u002Bb29f7UDXsp99Km48zx\u002BXUkHxYrdP5O4=","Zj1gozVje0UGK1srrd8TNGYUEXHzQpz/esP\u002BUaINhMs=","587UMkRW9Duvi09dG2y/rsS2zVrz865mHwElGvidCDE=","7HE6TnPvLegH\u002BkmPfdNuw7C6mM5Vgea4zehQVjDOli4="],"CachedAssets":{},"CachedCopyCandidates":{}} \ No newline at end of file +{"GlobalPropertiesHash":"kj0YdTIP9epXJ4ydBR9yaRr5OemJ36+FlRmnBdiGrUE=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["nGadCmuBEG\u002BKUP6Powa57G4ZzOO6ibT7XQKZuYm3g44=","elQhyiEcBZcCHMIxyXyx47S4otwc/MEXjAYU/dca/hQ=","XrkTC/5D0wT4Vj8udAqp\u002B2DDPMQ5H3P4YZDu2X62NzI=","chR\u002BAL8taCFTQytCSiXtu6MS2y5z2GmMYAK8xprfbvA=","QUvWOS2l6Gf\u002Bb29f7UDXsp99Km48zx\u002BXUkHxYrdP5O4=","Zj1gozVje0UGK1srrd8TNGYUEXHzQpz/esP\u002BUaINhMs=","587UMkRW9Duvi09dG2y/rsS2zVrz865mHwElGvidCDE=","2BIhuv/t6BVBKzkDXJ\u002BLBW5o61ISoGgjQ1cATL0tWlw="],"CachedAssets":{},"CachedCopyCandidates":{}} \ No newline at end of file diff --git a/src/Fengling.AuthService/obj/Debug/net10.0/rjsmrazor.dswa.cache.json b/src/Fengling.AuthService/obj/Debug/net10.0/rjsmrazor.dswa.cache.json index 8bef78b..657ca0a 100644 --- a/src/Fengling.AuthService/obj/Debug/net10.0/rjsmrazor.dswa.cache.json +++ b/src/Fengling.AuthService/obj/Debug/net10.0/rjsmrazor.dswa.cache.json @@ -1 +1 @@ -{"GlobalPropertiesHash":"cWEb6+iVjovCYrac7gX+Ogl5Z4cMpIEURSADGbv9ou0=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["nGadCmuBEG\u002BKUP6Powa57G4ZzOO6ibT7XQKZuYm3g44=","elQhyiEcBZcCHMIxyXyx47S4otwc/MEXjAYU/dca/hQ=","XrkTC/5D0wT4Vj8udAqp\u002B2DDPMQ5H3P4YZDu2X62NzI=","chR\u002BAL8taCFTQytCSiXtu6MS2y5z2GmMYAK8xprfbvA=","QUvWOS2l6Gf\u002Bb29f7UDXsp99Km48zx\u002BXUkHxYrdP5O4=","Zj1gozVje0UGK1srrd8TNGYUEXHzQpz/esP\u002BUaINhMs=","587UMkRW9Duvi09dG2y/rsS2zVrz865mHwElGvidCDE=","7HE6TnPvLegH\u002BkmPfdNuw7C6mM5Vgea4zehQVjDOli4="],"CachedAssets":{},"CachedCopyCandidates":{}} \ No newline at end of file +{"GlobalPropertiesHash":"cWEb6+iVjovCYrac7gX+Ogl5Z4cMpIEURSADGbv9ou0=","FingerprintPatternsHash":"gq3WsqcKBUGTSNle7RKKyXRIwh7M8ccEqOqYvIzoM04=","PropertyOverridesHash":"8ZRc1sGeVrPBx4lD717BgRaQekyh78QKV9SKsdt638U=","InputHashes":["nGadCmuBEG\u002BKUP6Powa57G4ZzOO6ibT7XQKZuYm3g44=","elQhyiEcBZcCHMIxyXyx47S4otwc/MEXjAYU/dca/hQ=","XrkTC/5D0wT4Vj8udAqp\u002B2DDPMQ5H3P4YZDu2X62NzI=","chR\u002BAL8taCFTQytCSiXtu6MS2y5z2GmMYAK8xprfbvA=","QUvWOS2l6Gf\u002Bb29f7UDXsp99Km48zx\u002BXUkHxYrdP5O4=","Zj1gozVje0UGK1srrd8TNGYUEXHzQpz/esP\u002BUaINhMs=","587UMkRW9Duvi09dG2y/rsS2zVrz865mHwElGvidCDE=","2BIhuv/t6BVBKzkDXJ\u002BLBW5o61ISoGgjQ1cATL0tWlw="],"CachedAssets":{},"CachedCopyCandidates":{}} \ No newline at end of file