Dot-Net

ACS75005 “請求不是有效的 SAML2 協議消息。”當我使用 SAML 連接到 Windows Azure Active Directory 時始終顯示

  • February 18, 2016

我正在嘗試將 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 請求,並且僅替換了一些值,但仍然收到相同的錯誤消息!

我的請求有什麼問題?以及如何獲得有關該消息的更多詳細資訊!

知道我的應用程序是在 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>

但仍然顯示相同的錯誤!

另請在此處找到我正在使用的測試項目。僅為您的 SAML 設置替換 webconfig 中 AppSettings 中的值。

採用

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 的編碼方式。我將其更改為標準的放氣編碼並且它有效。

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;
}

引用自:https://stackoverflow.com/questions/25120025