我有一个非常简单的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同意屏幕上后: