为什么标识服务器重定向到http而不是HTTPS? [英] Why is IdentityServer redirecting to http rather than https?
本文介绍了为什么标识服务器重定向到http而不是HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个非常简单的MVC5网站,我正在尝试使用IdentityServer3来保护它。
我的网站和我的身份服务器实例都在AppHarbor中作为单独的站点托管。两者都位于HTTPS之后。
当我访问网站中受[Authorize]
属性(例如/Home/About
)保护的资源时,我会被成功重定向到身份服务器,并且我可以成功进行身份验证。
app.FormPostResponse.js
),该网站将以302重定向到所请求的资源作为响应-正如预期的那样。但是,此重定向到http,而不是HTTPS(请参阅下面的网络跟踪)。
我确信这只是我的身份服务器配置有问题,但如果您能指出我的错误之处,我将不胜感激。
(AppHarbor在IIS前面使用反向代理(我相信是nginx),SSL端接在那里--因此,我为这个场景准备了RequireSsl = false
,根据标识服务器文档。)
这是我的网站Startup.cs
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "https://<my-idsrv3>.apphb.com/identity",
ClientId = "<my-client-id>",
Scope = "openid profile roles email",
RedirectUri = "https://<my-website>.apphb.com",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies",
UseTokenLifetime = false
});
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
}
}
以下是来自我的标识服务器3实例的Startup.cs:
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Map("/identity", idsrvApp =>
{
idsrvApp.UseIdentityServer(new IdentityServerOptions
{
SiteName = "My Identity Server",
SigningCertificate = Certificates.LoadSigningCertificate(),
RequireSsl = false,
PublicOrigin = "https://<my-idsrv3>.apphb.com",
Factory = new IdentityServerServiceFactory()
.UseInMemoryUsers(Users.Get())
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
});
});
}
}
以下是我的网站客户端的定义:
new Client
{
Enabled = true,
ClientName = "My Website Client",
ClientId = "<my-client-id>",
Flow = Flows.Implicit,
RedirectUris = new List<string>
{
"https://<my-website>.apphb.com"
},
AllowAccessToAllScopes = true
}
以下是在身份服务器同意屏幕上单击‘是,允许’后Chrome的跟踪结果:
推荐答案
因此,此问题似乎是由我的客户端网站位于终止SSLngix的前端之后引起的。
参考this GitHub issue,我在网站应用程序配置的开头添加了以下内容:
app.Use(async (ctx, next) =>
{
string proto = ctx.Request.Headers.Get("X-Forwarded-Proto");
if (!string.IsNullOrEmpty(proto))
{
ctx.Request.Scheme = proto;
}
await next();
});
这使网站知道传入的请求是通过HTTPS的;这反过来又似乎确保了标识服务器3中间件生成了HTTPS的URI。
这篇关于为什么标识服务器重定向到http而不是HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文