【问题标题】:WSFederationAuthenticationModule: RedirectToIdentityProvider: Does the realm have to be a subset of the request URL?WSFederationAuthenticationModule:RedirectToIdentityProvider:领域是否必须是请求 URL 的子集?
【发布时间】:2014-12-05 02:58:45
【问题描述】:

像许多其他在 .NET 中处理 WIF 的人一样,我遇到了常见的错误:

ID3206:SignInResponse 消息只能在当前 网络应用程序。

我编写了一个自定义身份验证模块,我按照Error - A SignInResponse message may only redirect within the current web application - MVC 2.0 application 中的建议覆盖了 RedirectToIdentityProvider。

建议的代码示例没有考虑到请求 URL 可能包含参数,即它只会在完整 URL 后附加一个斜杠。最终,我将该代码扩展为您在下面看到的内容,但仍使用领域来决定是否处理 URL:

Public Overrides Sub RedirectToIdentityProvider(ByVal uniqueId As String, ByVal returnUrl As String, ByVal persist As Boolean)
    Dim absoluteUri As String = HttpContext.Current.Request.Url.AbsoluteUri
    Dim ciAbsoluteUri As String = absoluteUri.ToLowerInvariant

    Dim realm As String = MyBase.Realm
    Dim ciRealm As String = realm.ToLowerInvariant

    'If Realm ends with a trailing slash, the returnUrl should include a trailing slash in the same position.
    'This trailing slash may or may not be the end of the returnUrl, depending on whether or not additional parameters have been provided.
    If realm.EndsWith("/") Then
        If Not ciAbsoluteUri.StartsWith(ciRealm) Then
            Dim realmWithoutSlash As String = realm.Substring(0, realm.Length - 1)
            Dim ciRealmWithoutSlash As String = realmWithoutSlash.ToLowerInvariant
            If ciAbsoluteUri.StartsWith(ciRealmWithoutSlash) Then
                'Realm ends with a slash and AbsoluteUri contains Realm but without a slash.
                Dim absolutePath As String = HttpContext.Current.Request.Url.AbsolutePath
                returnUrl = returnUrl.Replace(absolutePath, absolutePath & "/")
            End If
        End If
    End If

    MyBase.RedirectToIdentityProvider(uniqueId, returnUrl, persist)

End Sub

(这本可以写得更紧凑,但这不是重点。)

原帖中的代码包含以下注释

//Compare if Request Url +"/" is equal to the Realm, so only root access is corrected
//https://localhost/AppName plus "/" is equal to https://localhost/AppName/
//This is to avoid MVC urls

完全可以将 web.config 文件中的 realm 和 AudienceUri 以及 AD FS 2.0 端的标识符设置为请求 URL 的子集以外的值,只要该值是有效的 URI。例如,“http://corp.com”的虚假值就足够了。但是,使用这样的值意味着请求 URL 不会被 RedirectToIdentityProvider 覆盖处理。

我的问题是:

在 MVC 应用程序中让领域成为请求 URL 的子集的原因是什么?更重要的是,非 MVC 应用程序是否有同样的要求?

我可以不忽略领域并确保 URL 在末尾(如果没有参数的情况下)或参数列表之前包含斜杠吗?

【问题讨论】:

    标签: asp.net vb.net wif adfs ws-federation


    【解决方案1】:

    只是一些基础知识:Realm 是元数据中 EntityID 的 WIF 语言。它应该是一个 URI。这意味着它不必是 URL。几乎所有实现都非常宽容,并且接受 EntityID 中的任何字符串。
    在这种情况下,returnurl 表示在用户通过身份验证并且 WIF 设置会话 cookie 后浏览器将转到的 url。它应该在应用程序中(为什么还要进行身份验证)。如果您确实想要应用程序根目录,那么结束斜线确实是一个好主意(因为 cookiepath)。所以 Realm 的使用(在这种特殊情况下)是一个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多