From 498363e5fcf0022cf06786ab8d03c59382ef3578 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 25 Jan 2022 13:41:45 +0300 Subject: [PATCH] Updated identityserver data seeder to seed multiple redirect uris --- .../DbMigrations/IdentityServerDataSeeder.cs | 100 +++++++++++------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs index a5facdf7..c7caf15d 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs @@ -105,29 +105,16 @@ namespace EShopOnAbp.IdentityService.DbMigrations private async Task CreateSwaggerClientsAsync() { - await CreateSwaggerClientAsync("AccountService", - new[] { "AccountService"}); - - await CreateSwaggerClientAsync("IdentityService", - new[] { "IdentityService"}); - - await CreateSwaggerClientAsync("AdministrationService", - new[] { "AdministrationService" }); - - await CreateSwaggerClientAsync("CatalogService", - new[] { "CatalogService" }); - - await CreateSwaggerClientAsync("BasketService", - new[] { "BasketService" }); - - await CreateSwaggerClientAsync("OrderingService", - new[] { "OrderingService" }); - - await CreateSwaggerClientAsync("PaymentService", - new[] { "PaymentService" }); + await CreateWebGatewaySwaggerClientAsync("WebGateway", + new[] + { + "AccountService", "IdentityService", "AdministrationService", + "CatalogService", "BasketService", + "PaymentService", "OrderingService" + }); } - private async Task CreateSwaggerClientAsync(string name, string[] scopes = null) + private async Task CreateWebGatewaySwaggerClientAsync(string name, string[] scopes = null) { var commonScopes = new[] { @@ -138,22 +125,51 @@ namespace EShopOnAbp.IdentityService.DbMigrations "phone", "address" }; - scopes ??= new[] { name }; + scopes ??= new[] {name}; // Swagger Client var swaggerClientId = $"{name}_Swagger"; if (!swaggerClientId.IsNullOrWhiteSpace()) { - var swaggerRootUrl = _configuration[$"IdentityServerClients:{name}:RootUrl"].TrimEnd('/'); + var webGatewaySwaggerRootUrl = _configuration[$"IdentityServerClients:{name}:RootUrl"].TrimEnd('/'); + var publicWebGatewayRootUrl = _configuration[$"IdentityServerClients:PublicWebGateway:RootUrl"].TrimEnd('/'); + var accountServiceRootUrl = _configuration[$"IdentityServerClients:AccountService:RootUrl"].TrimEnd('/'); + var identityServiceRootUrl = _configuration[$"IdentityServerClients:IdentityService:RootUrl"].TrimEnd('/'); + var administrationServiceRootUrl = _configuration[$"IdentityServerClients:AdministrationService:RootUrl"].TrimEnd('/'); + var catalogServiceRootUrl = _configuration[$"IdentityServerClients:CatalogService:RootUrl"].TrimEnd('/'); + var basketServiceRootUrl = _configuration[$"IdentityServerClients:BasketService:RootUrl"].TrimEnd('/'); + var orderingServiceRootUrl = _configuration[$"IdentityServerClients:OrderingService:RootUrl"].TrimEnd('/'); + var paymentServiceRootUrl = _configuration[$"IdentityServerClients:PaymentService:RootUrl"].TrimEnd('/'); await CreateClientAsync( name: swaggerClientId, scopes: commonScopes.Union(scopes), - grantTypes: new[] { "authorization_code" }, + grantTypes: new[] {"authorization_code"}, secret: "1q2w3e*".Sha256(), requireClientSecret: false, - redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html", - corsOrigins: new[] { swaggerRootUrl.RemovePostFix("/") } + redirectUris: new List + { + $"{webGatewaySwaggerRootUrl}/swagger/oauth2-redirect.html", // WebGateway redirect uri + $"{publicWebGatewayRootUrl}/swagger/oauth2-redirect.html", // PublicWebGateway redirect uri + $"{accountServiceRootUrl}/swagger/oauth2-redirect.html", // AccountService redirect uri + $"{identityServiceRootUrl}/swagger/oauth2-redirect.html", // IdentityService redirect uri + $"{administrationServiceRootUrl}/swagger/oauth2-redirect.html", // AdministrationService redirect uri + $"{catalogServiceRootUrl}/swagger/oauth2-redirect.html", // CatalogService redirect uri + $"{basketServiceRootUrl}/swagger/oauth2-redirect.html", // BasketService redirect uri + $"{orderingServiceRootUrl}/swagger/oauth2-redirect.html", // OrderingService redirect uri + $"{paymentServiceRootUrl}/swagger/oauth2-redirect.html" // PaymentService redirect uri + }, + corsOrigins: new[] + { + webGatewaySwaggerRootUrl.RemovePostFix("/"), + publicWebGatewayRootUrl.RemovePostFix("/"), + accountServiceRootUrl.RemovePostFix("/"), + administrationServiceRootUrl.RemovePostFix("/"), + catalogServiceRootUrl.RemovePostFix("/"), + basketServiceRootUrl.RemovePostFix("/"), + orderingServiceRootUrl.RemovePostFix("/"), + paymentServiceRootUrl.RemovePostFix("/") + } ); } } @@ -186,7 +202,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations private async Task CreateApiScopeAsync(string name) { - var apiScope = await _apiScopeRepository.FindByNameAsync(name ); + var apiScope = await _apiScopeRepository.FindByNameAsync(name); if (apiScope == null) { apiScope = await _apiScopeRepository.InsertAsync( @@ -228,12 +244,12 @@ namespace EShopOnAbp.IdentityService.DbMigrations "PaymentService", "OrderingService" }), - grantTypes: new[] { "hybrid" }, + grantTypes: new[] {"hybrid"}, secret: "1q2w3e*".Sha256(), - redirectUri: $"{publicWebClientRootUrl}signin-oidc", + redirectUris: new List{ $"{publicWebClientRootUrl}signin-oidc" }, postLogoutRedirectUri: $"{publicWebClientRootUrl}signout-callback-oidc", frontChannelLogoutUri: $"{publicWebClientRootUrl}Account/FrontChannelLogout", - corsOrigins: new[] { publicWebClientRootUrl.RemovePostFix("/") } + corsOrigins: new[] {publicWebClientRootUrl.RemovePostFix("/")} ); //Angular Client @@ -247,13 +263,13 @@ namespace EShopOnAbp.IdentityService.DbMigrations "IdentityService", "AdministrationService" }), - grantTypes: new[] { "authorization_code", "LinkLogin", "password" }, + grantTypes: new[] {"authorization_code", "LinkLogin", "password"}, secret: "1q2w3e*".Sha256(), requirePkce: true, requireClientSecret: false, - redirectUri: $"{angularClientRootUrl}", + redirectUris: new List{ $"{angularClientRootUrl}" }, postLogoutRedirectUri: $"{angularClientRootUrl}", - corsOrigins: new[] { angularClientRootUrl } + corsOrigins: new[] {angularClientRootUrl} ); //Administration Service Client @@ -263,9 +279,9 @@ namespace EShopOnAbp.IdentityService.DbMigrations { "IdentityService" }), - grantTypes: new[] { "client_credentials" }, + grantTypes: new[] {"client_credentials"}, secret: "1q2w3e*".Sha256(), - permissions: new[] { IdentityPermissions.Users.Default } + permissions: new[] {IdentityPermissions.Users.Default} ); } @@ -274,7 +290,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations IEnumerable scopes, IEnumerable grantTypes, string secret = null, - string redirectUri = null, + List redirectUris = null, string postLogoutRedirectUri = null, string frontChannelLogoutUri = null, bool requireClientSecret = true, @@ -333,11 +349,17 @@ namespace EShopOnAbp.IdentityService.DbMigrations } } - if (redirectUri != null) + if (redirectUris != null) { - if (client.FindRedirectUri(redirectUri) == null) + foreach (var redirectUri in redirectUris) { - client.AddRedirectUri(redirectUri); + if (redirectUri != null) + { + if (client.FindRedirectUri(redirectUri) == null) + { + client.AddRedirectUri(redirectUri); + } + } } }