【发布时间】:2018-02-12 14:39:15
【问题描述】:
我有一个非常简单的 MVC5 网站,我正在尝试使用 IdentityServer3 来保护它。
我的网站和我的 IdentityServer 实例都在 AppHarbor 中作为单独的站点托管。两者都落后于 https。
当我在我的网站中访问受[Authorize] 属性(例如/Home/About)保护的资源时,我被成功重定向到 IdentityServer,并且我可以成功进行身份验证。
当 IdentityServer 将其响应 POST 回网站(通过app.FormPostResponse.js)时,网站会以 302 重定向响应请求的资源 - 正如预期的那样。但是,此重定向是到 http,而不是 https(请参阅下面的网络跟踪)。
我确定这只是我的 IdentityServer 配置有问题,但我会感谢任何关于我有什么问题的指针。
(AppHarbor 在 IIS 前使用反向代理(我相信是 nginx),SSL 会在此处终止 - 所以我有 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>();
}
}
这是来自我的 IdentityServer3 实例的 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 的跟踪,在 IdentityServer 同意屏幕上单击“是,允许”后:
【问题讨论】:
标签: identityserver3 openid-connect appharbor