我在使用时遇到登录循环问题WsFederation Authentication
在我的 MVC Web 应用程序中。我使用 Visual Studio 创建 Web 应用程序的脚手架并设置WsFederation
in the Startup.cs
。它生成以下代码块:
public class Startup
{
private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
}
}
Web 应用程序托管在 Azure 中,ADFS 位于本地。
在某些客户端上,当尝试登录时,登录页面会进入循环,请求新令牌,从而导致 ADFS 服务器上出现以下异常:
异常详细信息:
Microsoft.IdentityServer.Web.InvalidRequestException:MSIS7042:同一客户端浏览器会话在过去“7”秒内发出了“6”个请求。请联系您的管理员了解详细信息。
我读过 StackOverflow 上的很多文章,查看了编写 IdentityServer 的人提供的各种示例,并且尝试了各种配置选项,但无法将问题隔离到特定区域。
据我所知,这是 OWIN 中间件丢失对象上下文的普遍问题,因此令牌“丢失”。
我曾尝试实施其中的一些示例代码其他人在 StackOverflow 上提供了这些内容,但是我似乎找不到解决我的问题的解决方案,或者可能没有正确实现代码。
有任何想法吗?
问题的原因是请求和响应 URL 不相同。 IE。当用户输入网站 URL 且未使用 HTTPS 前缀时,就会发生重定向循环。
原因是隐藏的,因为如果用户未经身份验证或授权,他们会立即重定向到 ADFS。
我所要做的就是确保所有用户请求都重定向回 HTTPS URL 并删除 HTTP 绑定。(要么 要么 都可以正常工作)
这是我用来确保所有请求都重定向到 https 的代码。
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
我希望这篇文章对您有所帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)