Browse Source

Updated identityserver data seeder to seed multiple redirect uris

pull/68/head
Galip Tolga Erdem 5 years ago
parent
commit
498363e5fc
  1. 100
      services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs

100
services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/DbMigrations/IdentityServerDataSeeder.cs

@ -105,29 +105,16 @@ namespace EShopOnAbp.IdentityService.DbMigrations
private async Task CreateSwaggerClientsAsync() private async Task CreateSwaggerClientsAsync()
{ {
await CreateSwaggerClientAsync("AccountService", await CreateWebGatewaySwaggerClientAsync("WebGateway",
new[] { "AccountService"}); new[]
{
await CreateSwaggerClientAsync("IdentityService", "AccountService", "IdentityService", "AdministrationService",
new[] { "IdentityService"}); "CatalogService", "BasketService",
"PaymentService", "OrderingService"
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" });
} }
private async Task CreateSwaggerClientAsync(string name, string[] scopes = null) private async Task CreateWebGatewaySwaggerClientAsync(string name, string[] scopes = null)
{ {
var commonScopes = new[] var commonScopes = new[]
{ {
@ -138,22 +125,51 @@ namespace EShopOnAbp.IdentityService.DbMigrations
"phone", "phone",
"address" "address"
}; };
scopes ??= new[] { name }; scopes ??= new[] {name};
// Swagger Client // Swagger Client
var swaggerClientId = $"{name}_Swagger"; var swaggerClientId = $"{name}_Swagger";
if (!swaggerClientId.IsNullOrWhiteSpace()) 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( await CreateClientAsync(
name: swaggerClientId, name: swaggerClientId,
scopes: commonScopes.Union(scopes), scopes: commonScopes.Union(scopes),
grantTypes: new[] { "authorization_code" }, grantTypes: new[] {"authorization_code"},
secret: "1q2w3e*".Sha256(), secret: "1q2w3e*".Sha256(),
requireClientSecret: false, requireClientSecret: false,
redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html", redirectUris: new List<string>
corsOrigins: new[] { swaggerRootUrl.RemovePostFix("/") } {
$"{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<ApiScope> CreateApiScopeAsync(string name) private async Task<ApiScope> CreateApiScopeAsync(string name)
{ {
var apiScope = await _apiScopeRepository.FindByNameAsync(name ); var apiScope = await _apiScopeRepository.FindByNameAsync(name);
if (apiScope == null) if (apiScope == null)
{ {
apiScope = await _apiScopeRepository.InsertAsync( apiScope = await _apiScopeRepository.InsertAsync(
@ -228,12 +244,12 @@ namespace EShopOnAbp.IdentityService.DbMigrations
"PaymentService", "PaymentService",
"OrderingService" "OrderingService"
}), }),
grantTypes: new[] { "hybrid" }, grantTypes: new[] {"hybrid"},
secret: "1q2w3e*".Sha256(), secret: "1q2w3e*".Sha256(),
redirectUri: $"{publicWebClientRootUrl}signin-oidc", redirectUris: new List<string>{ $"{publicWebClientRootUrl}signin-oidc" },
postLogoutRedirectUri: $"{publicWebClientRootUrl}signout-callback-oidc", postLogoutRedirectUri: $"{publicWebClientRootUrl}signout-callback-oidc",
frontChannelLogoutUri: $"{publicWebClientRootUrl}Account/FrontChannelLogout", frontChannelLogoutUri: $"{publicWebClientRootUrl}Account/FrontChannelLogout",
corsOrigins: new[] { publicWebClientRootUrl.RemovePostFix("/") } corsOrigins: new[] {publicWebClientRootUrl.RemovePostFix("/")}
); );
//Angular Client //Angular Client
@ -247,13 +263,13 @@ namespace EShopOnAbp.IdentityService.DbMigrations
"IdentityService", "IdentityService",
"AdministrationService" "AdministrationService"
}), }),
grantTypes: new[] { "authorization_code", "LinkLogin", "password" }, grantTypes: new[] {"authorization_code", "LinkLogin", "password"},
secret: "1q2w3e*".Sha256(), secret: "1q2w3e*".Sha256(),
requirePkce: true, requirePkce: true,
requireClientSecret: false, requireClientSecret: false,
redirectUri: $"{angularClientRootUrl}", redirectUris: new List<string>{ $"{angularClientRootUrl}" },
postLogoutRedirectUri: $"{angularClientRootUrl}", postLogoutRedirectUri: $"{angularClientRootUrl}",
corsOrigins: new[] { angularClientRootUrl } corsOrigins: new[] {angularClientRootUrl}
); );
//Administration Service Client //Administration Service Client
@ -263,9 +279,9 @@ namespace EShopOnAbp.IdentityService.DbMigrations
{ {
"IdentityService" "IdentityService"
}), }),
grantTypes: new[] { "client_credentials" }, grantTypes: new[] {"client_credentials"},
secret: "1q2w3e*".Sha256(), secret: "1q2w3e*".Sha256(),
permissions: new[] { IdentityPermissions.Users.Default } permissions: new[] {IdentityPermissions.Users.Default}
); );
} }
@ -274,7 +290,7 @@ namespace EShopOnAbp.IdentityService.DbMigrations
IEnumerable<string> scopes, IEnumerable<string> scopes,
IEnumerable<string> grantTypes, IEnumerable<string> grantTypes,
string secret = null, string secret = null,
string redirectUri = null, List<string> redirectUris = null,
string postLogoutRedirectUri = null, string postLogoutRedirectUri = null,
string frontChannelLogoutUri = null, string frontChannelLogoutUri = null,
bool requireClientSecret = true, 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);
}
}
} }
} }

Loading…
Cancel
Save