Fix swagger-ui redirection uri to current one as of v.3.x;
Fix stored values for existing deployments
This commit is contained in:
parent
fc81bb985b
commit
cdd87d367f
@ -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 =
|
||||
|
@ -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<ClientRedirectUri> 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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user