我有一个非常简单的MVC5网站,我试图用IdentityServer3来保护。为什么IdentityServer重定向到http而不是https?
我的网站和我的IdentityServer实例都作为AppHarbor中的独立站点托管。两者都支持https。
当我在我的网站中受到[Authorize]属性(例如,/Home/About)保护的资源时,我已成功重定向到IdentityServer,并且我可以成功进行身份验证。
当IdentityServer将其响应发回到网站(通过app.FormPostResponse.js)后,网站将302重定向到所请求的资源 - 如预期。但是,此重定向是http,而不是https(请参阅下面的网络跟踪)。
我敢肯定,这只是我的IdentityServer配置错了,但我会很感激任何指针,我有什么问题。
(AppHarbor使用在IIS中,在SSL终止前的反向代理(nginx的我相信) - 所以我有RequireSsl = false此情况下,如按照IdentityServer文档)
这里是我的网站的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>();
}
}
这里是Startup.cs从我IdentityServer3例如:
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的痕迹,点击“是的,允许”的IdentityServer同意屏幕上后:
所以看起来这个问题是我的客户的网站引起在SSL终结nginx前端后面。
参考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;这反过来似乎确保IdentityServer3中间件生成https URI。
本文链接:https://blog.nnwk.net/article/54
有问题请留言。版权所有,转载请在显眼位置处保留文章出处,并留下原文连接
Leave your question and I'll get back to you as soon as I see it. All rights reserved. Please keep the source and links
友情链接:
子卿全栈
全部评论