【发布时间】:2019-03-02 00:00:03
【问题描述】:
使用 Asp.Net Core 2.1.4。该应用程序位于从 https://github.com/jwilder/nginx-proxy docker 映像运行的 Nginx 反向代理后面,其中包括 x-forwarded-* 标头配置。
在我的Startup.Configure 方法中,我做的第一件事是:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.All
});
然后在 ConfigureServices 中设置外部身份验证:
services.AddAuthentication().AddFacebook(facebookOptions =>
{
facebookOptions.AppId = Configuration["FacebookAppId"];
facebookOptions.AppSecret = Configuration["FacebookSecret"];
})
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = Configuration["GoogleClientId"];
googleOptions.ClientSecret = Configuration["GoogleClientSecret"];
});
并配置身份:
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<IdentityDbContext>()
.AddDefaultTokenProviders();
然后我有一个控制器操作,我的登录表单发布到:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
HTTP 适用于整个站点。我可以在 Chrome 开发工具中看到通向“ExternalLogin”的路由的调用是通过 https 进行的,但是应用程序会将我重定向到 Facebook 或 Google,并使用 http 的 redirect_uri。在验证并重定向回 http url 后,我的应用会自动重定向到 https。
如何让 Identity 生成安全的重定向 uri?
【问题讨论】:
标签: c# asp.net-core asp.net-identity