diff --git a/global.json b/global.json index 2ab18dceb..00b3f36f2 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { - "sdk": { - "version":"2.1.2" - } + "sdk": { + "version": "2.1.4" + } } \ No newline at end of file diff --git a/src/Services/Identity/Identity.API/Configuration/Config.cs b/src/Services/Identity/Identity.API/Configuration/Config.cs index 3bc705995..301cccba2 100644 --- a/src/Services/Identity/Identity.API/Configuration/Config.cs +++ b/src/Services/Identity/Identity.API/Configuration/Config.cs @@ -162,7 +162,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["LocationsApi"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["LocationsApi"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["LocationsApi"]}/swagger/" }, AllowedScopes = @@ -177,7 +177,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["MarketingApi"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["MarketingApi"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["MarketingApi"]}/swagger/" }, AllowedScopes = @@ -192,7 +192,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["BasketApi"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["BasketApi"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["BasketApi"]}/swagger/" }, AllowedScopes = @@ -207,7 +207,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["OrderingApi"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["OrderingApi"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["OrderingApi"]}/swagger/" }, AllowedScopes = @@ -222,7 +222,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["MobileShoppingAgg"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["MobileShoppingAgg"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["MobileShoppingAgg"]}/swagger/" }, AllowedScopes = @@ -237,7 +237,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Configuration AllowedGrantTypes = GrantTypes.Implicit, AllowAccessTokensViaBrowser = true, - RedirectUris = { $"{clientsUrl["WebShoppingAgg"]}/swagger/o2c.html" }, + RedirectUris = { $"{clientsUrl["WebShoppingAgg"]}/swagger/oauth2-redirect.html" }, PostLogoutRedirectUris = { $"{clientsUrl["WebShoppingAgg"]}/swagger/" }, AllowedScopes = diff --git a/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs b/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs index a5a4383bd..3547c053a 100644 --- a/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs +++ b/src/Services/Identity/Identity.API/Data/ConfigurationDbContextSeed.cs @@ -1,7 +1,10 @@ using IdentityServer4.EntityFramework.DbContexts; +using IdentityServer4.EntityFramework.Entities; using IdentityServer4.EntityFramework.Mappers; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.Services.Identity.API.Configuration; using Microsoft.Extensions.Configuration; +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -30,16 +33,37 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data { foreach (var client in Config.GetClients(clientUrls)) { - await context.Clients.AddAsync(client.ToEntity()); + context.Clients.Add(client.ToEntity()); } await context.SaveChangesAsync(); } + // Checking always for old redirects to fix existing deployments + // to use new swagger-ui redirect uri as of v3.0.0 + // There should be no problem for new ones + // ref: https://github.com/dotnet-architecture/eShopOnContainers/issues/586 + else + { + List oldRedirects = (await context.Clients.Include(c => c.RedirectUris).ToListAsync()) + .SelectMany(c => c.RedirectUris) + .Where(ru => ru.RedirectUri.EndsWith("/o2c.html")) + .ToList(); + + if (oldRedirects.Any()) + { + foreach (var ru in oldRedirects) + { + ru.RedirectUri = ru.RedirectUri.Replace("/o2c.html", "/oauth2-redirect.html"); + context.Update(ru.Client); + } + await context.SaveChangesAsync(); + } + } if (!context.IdentityResources.Any()) { foreach (var resource in Config.GetResources()) { - await context.IdentityResources.AddAsync(resource.ToEntity()); + context.IdentityResources.Add(resource.ToEntity()); } await context.SaveChangesAsync(); } @@ -48,7 +72,7 @@ namespace Microsoft.eShopOnContainers.Services.Identity.API.Data { foreach (var api in Config.GetApis()) { - await context.ApiResources.AddAsync(api.ToEntity()); + context.ApiResources.Add(api.ToEntity()); } await context.SaveChangesAsync();