【问题标题】:ACS75005 "The request is not a valid SAML2 protocol message." Is showing always when I connect to Windows Azure Active Directory using SAMLACS75005 “请求不是有效的 SAML2 协议消息。”当我使用 SAML 连接到 Windows Azure Active Directory 时始终显示
【发布时间】:2014-08-04 13:37:58
【问题描述】:

我正在尝试将 Windows Azure Active Directory 用作 Web 应用程序中的 IdP。我的代码在其他 SAML IdP 上运行良好,但仅在 Windows Azure AD 中提供以下消息!

登录

抱歉,我们无法让您登录。

我们收到了错误的请求。 其他技术信息:

跟踪 ID:8377e605-6b9f-47be-8547-5fce7f4285af

时间戳:2014-08-04 13:31:27Z

ACS75005:

请求不是有效的 SAML2 协议消息。

我替换了我的代码并使用了 Microsoft 发布的 SAML 请求 here,并且只替换了一些值,但仍然收到相同的错误消息!!

我的请求有什么问题?以及如何获得有关该消息的更多详细信息!

知道我的应用程序是在 Windows Azure AD 应用程序中定义的。

<samlp:AuthnRequest xmlns="urn:oasis:names:tc:SAML:2.0:metadata" ID="_56dbfeac-107a-46d2-b989-651f90107312" Version="2.0" IssueInstant="2014-08-04T13:28:05Z" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">SOMETHING</Issuer> 
</samlp:AuthnRequest>

编辑 001 将断言编辑为 Dushyant 建议的内容后,它变为:

<samlp:AuthnRequest xmlns="urn:oasis:names:tc:SAML:2.0:assertion" 
    ID="_efcebb45-5ee6-42df-ace4-a343f28f5a46"                                                 
    Version="2.0" IssueInstant="2014-08-07T06:29:09Z"                                                 
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">                                    
    <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">SOMETHING</Issuer>
</samlp:AuthnRequest>

但仍然显示相同的错误!

另外请找到我正在使用的测试项目here。仅为您的 SAML 设置替换 webconfig 中 AppSettings 中的值。

【问题讨论】:

  • 我发现了问题。请看我修改后的答案。
  • 呸!死链接。在 StackOverflow 上,最好内联所有内容。

标签: .net azure saml-2.0


【解决方案1】:

使用

xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"

而不是 xmlns="urn:oasis:names:tc:SAML:2.0:metadata"

我相信您遵循了我们在此处记录的内容:http://msdn.microsoft.com/en-us/library/azure/dn195589.aspx。如果是这样,您在该文章中发现了一个错误 - 对此感到抱歉。

希望这会有所帮助。


Homam,我查看了您的代码。问题在于 AuthnRequest 的编码方式。我将其更改为标准的 deflate 编码并且它起作用了。

public string GetAzureRequest(AuthRequestFormat format)
{
    string xml = @"<samlp:AuthnRequest xmlns=""urn:oasis:names:tc:SAML:2.0:assertion"" ID=""#ID""
                                     Version=""2.0"" IssueInstant=""#DATE""
                                     xmlns:samlp=""urn:oasis:names:tc:SAML:2.0:protocol"">
                        <Issuer xmlns=""urn:oasis:names:tc:SAML:2.0:assertion"">#ISSUER</Issuer>
                 </samlp:AuthnRequest>";

    xml = xml.Replace("#DATE", issue_instant);
    xml = xml.Replace("#ID", id);
    xml = xml.Replace("#ISSUER", appSettings.Issuer);
    xml = xml.Replace("\r\n", "");

    if (format == AuthRequestFormat.Base64)
    {
        /*COMMENTED THIS OUT*/

        //byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(requestDocument.OuterXml);
        //string result = System.Convert.ToBase64String(toEncodeAsBytes);
        //return result;


        /*ADDED THIS*/

        MemoryStream memoryStream = new MemoryStream();
        StreamWriter writer = new StreamWriter(new DeflateStream(memoryStream, CompressionMode.Compress, true), new UTF8Encoding(false));
        writer.Write(xml);
        writer.Close();
        string result = Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)memoryStream.Length, Base64FormattingOptions.None);
        return result;
    }

    return null;
}

【讨论】:

  • 仍然是同样的错误,没有详细信息:(请帮助我,直到我修复它。
  • 已编辑问题.. 更新位于“Edit 001
  • 我还在问题中添加了我正在使用的示例代码
  • 非常感谢。我一直在努力寻找一种解决方案来为 Azure AD 登录请求编写 SAMLRequest 查询字符串。此代码有效..!
【解决方案2】:

在 Get 请求中使用“结果”之前,您需要对其进行 UrlEncode(例如 HttpUtility.UrlEncode(result))。

【讨论】:

    【解决方案3】:

    我认为这里的命名空间不匹配...SAMLRequest 应该如下所示。

    <samlp:AuthnRequest
        ID="_efcebb45-5ee6-42df-ace4-a343f28f5a46"                                                 
        Version="2.0" IssueInstant="2014-08-07T06:29:09Z"                                                 
        xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">                                    
        <Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">SOMETHING</Issuer>
    </samlp:AuthnRequest>
    

    Issuer 元素必须在 'urn:oasis:names:tc:SAML:2.0:assertion' 的命名空间中,并且 AuthnRequest 元素必须在 'urn:oasis:names:tc:SAML:2.0:protocol' 的命名空间中

    当然这需要放气 + base64 编码。如果使用 HttpRedirect 绑定,那么在嵌入 URL 之前也要对其进行 urlencode

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 1970-01-01
      • 2012-08-05
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      相关资源
      最近更新 更多