我有一个 ASP.NET Core 应用程序,它使用 Azure Active Directory B2C 进行身份验证,并将其部署到 Google App Engine 实例中。在 AD B2C 中的应用程序配置中,我有 https://<domain>/signin-oid
作为我的重定向 URL,但是当我登录时出现错误 AADB2C90006
说域名http://<domain>/signin-oid
是无效的。我没有http
在我的代码中的任何位置指定的此 url 的版本。
我尝试在我的开发环境中本地运行它,它按预期工作。据我了解,Nginx 在启动的 Kestrel 实例之前充当代理,并且我已在 Kestrel 实例中配置 SSL 以使用 App Engine 实例使用的相同证书。我提到这一点是因为我怀疑 App Engine 和 Kestrel 配置之间存在某种脱节,尽管问题可能出在哪里还很模糊。
return new WebHostBuilder()
.ConfigureKestrel((context, options) =>
{
if (!string.IsNullOrEmpty(aspEnv) && !string.Equals(aspEnv,"Development"))
{
options.ListenAnyIP(443,opt => opt.UseHttps("myfile.pfx","mypass"));
}
})
我的 Configure
中也有这一行功能:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
最佳答案
好吧,我仍然不知道为什么 http:
会通过而不是 https:
,但我确实有一个修复它。
在我的项目中,我有一个名为 OpenIdConnectOptionsSetup
的类,它是我从 Azure AD B2C sample 中获取的。 。在此类中,我配置了 OpenIdConnectEvents
,其中包括一个 OnRedirectToIdentityProvider
委托(delegate),其中我有一些代码在查找 http:
但埋藏在 中if
语句寻找身份验证策略中的差异,我还没有看到调用的代码,但我离题了。
我的代表现在看起来像这样:
public Task OnRedirectToIdentityProviderAsync(RedirectContext context)
{
Logger.LogInformation($"redirect URI for B2C: {context.ProtocolMessage.RedirectUri} !!!!!!!");
if (context.ProtocolMessage.RedirectUri.Contains("http:"))
{
Logger.LogInformation("http: found in RedirectUri, replacing with https");
context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http:", "https:");
}
//in case of error, show us the problem
if (string.IsNullOrEmpty(context.ProtocolMessage.ErrorUri))
{
Logger.LogInformation("ErrorUri is empty! replacing with ErrorUri property.");
context.ProtocolMessage.ErrorUri = GCPSettings.ErrorUri;
}
}
通过此配置,我能够使用 Azure AD B2C 成功登录到我的站点。
关于asp.net-core - AADB2C90006 在redirect_uri 中具有 https-> http 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54334040/