【发布时间】:2017-03-16 04:53:40
【问题描述】:
我正在使用 Ws-Fed 身份验证 OWIN 中间件来使用 ADFS 对带有 Web API 端点的 ASP.NET MVC 应用程序进行身份验证。我可以使用 ADFS 成功登录,并且在我的 MVC 控制器上,HttpContext.User.Identity.IsAuthenticated 为真 - 我也可以看到已登录用户的声明信息。
但是,对于 WebAPI 端点,User.Identity.IsAuthenticated 为 false。已签名用户的声明信息也不可用。有什么方法可以公开用户已针对 MVC 和 WebAPI 控制器进行身份验证的事实?
这是我在 OWIN 启动类中配置身份验证中间件的方式:
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
ExpireTimeSpan = TimeSpan.FromMinutes(sessionDuration),
SlidingExpiration = true //expiration extended after each request
});
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = metadata,
Notifications = new WsFederationAuthenticationNotifications
{
AuthenticationFailed = context =>
{
context.HandleResponse();
context.Response.Redirect("/?loginfailed=loginfailed");
return Task.FromResult(0);
}
}
});
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 asp.net-web-api