###前提・実現したいこと
ADFSに対してSAMLリクエストを投げ、SAMLレスポンスを受け取りたいです。
###発生している問題・エラーメッセージ
ADFSに対してSAMLリクエストを投げた後、ADFS側で下記のエラーが発生しています。
System.Xml.XmlException: 名前の先頭に '.' (16 進数値 0x00) を使用することはできません。 行 1、位置 2。 場所 System.Xml.XmlTextReaderImpl.Throw(String res, String[] args) 場所 System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos) 場所 System.Xml.XmlTextReaderImpl.ParseElement() 場所 System.Xml.XmlTextReaderImpl.ParseDocumentContent() 場所 Microsoft.IdentityServer.Protocols.Saml.XmlNamespaceReader.Read() 場所 System.Xml.XmlReader.MoveToContent() 場所 System.Xml.XmlReader.IsStartElement(String localname, String ns) 場所 Microsoft.IdentityServer.Protocols.Saml.SamlProtocolSerializer.ReadSamlMessage(XmlReader reader, NamespaceContext context) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpSamlBindingSerializer.ReadProtocolMessage(String encodedSamlMessage) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpSamlBindingSerializer.CreateFromNameValueCollection(Uri baseUrl, NameValueCollection collection) 場所 Microsoft.IdentityServer.Protocols.Saml.HttpRedirectSamlBindingSerializer.ReadMessage(Uri requestUrl, NameValueCollection form) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.HttpSamlMessageFactory.CreateMessage(WrappedHttpListenerRequest httpRequest) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.SamlContextFactory.CreateProtocolContextFromRequest(WrappedHttpListenerRequest request, ProtocolContext& protocolContext) 場所 Microsoft.IdentityServer.Web.Protocols.Saml.SamlProtocolHandler.CreateProtocolContext(WrappedHttpListenerRequest request) 場所 Microsoft.IdentityServer.Web.PassiveProtocolListener.GetProtocolHandler(WrappedHttpListenerRequest request, ProtocolContext& protocolContext, PassiveProtocolHandler& protocolHandler) 場所 Microsoft.IdentityServer.Web.PassiveProtocolListener.OnGetContext(WrappedHttpListenerContext context)
###該当のソースコード
C#
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 #region Deflateエンコード 4 byte[] deflateEncodedSamlRequestBytes = null; 5 6 XmlDocument samlRequestXmlDoc = new XmlDocument(); 7 samlRequestXmlDoc.Load(@"C:\samlrequest.xml"); 8 9 byte[] samlRequestBytes = Encoding.Unicode.GetBytes(samlRequestXmlDoc.InnerXml); 10 using (MemoryStream samlRequestMemoryStream = new MemoryStream()) 11 { 12 using (DeflateStream samlRequestCompressedStream = new DeflateStream(samlRequestMemoryStream, CompressionMode.Compress, true)) 13 { 14 // エンコード 15 samlRequestCompressedStream.Write(samlRequestBytes, 0, samlRequestBytes.Length); 16 } 17 18 deflateEncodedSamlRequestBytes = samlRequestMemoryStream.ToArray(); 19 } 20 #endregion Deflateエンコード 21 22 // Base64エンコード 23 string base64EncodedSamlRequestString = Convert.ToBase64String(deflateEncodedSamlRequestBytes); 24 25 // URLエンコード 26 string urlEncodedSamlRequestString = HttpUtility.UrlEncode(base64EncodedSamlRequestString); 27 28 //--- AuthnRequestをキャッシュさせないために必要。 29 Response.Cache.SetCacheability(HttpCacheability.NoCache); 30 Response.Cache.SetNoStore(); 31 32 // SAMLリクエスト 33 Response.Redirect(string.Format("https://adfs-test.xxx.co.jp/adfs/ls?SAMLRequest={0}", urlEncodedSamlRequestString)); 34 }
※「samlrequest.xml」の内容は下記の通りです。
XML
1<?xml version="1.0" encoding="UTF-8"?><samlp:AuthnRequest AssertionConsumerServiceURL="https://firebrick.xx.xx.co.jp/SamlAuthTest/SamlAssertionConsumerService.aspx" ID="szqd0c3d0u3vpz5jwna4p24iso42opc4" IssueInstant="2013-04-01T00:00:00Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0" xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://firebrick.xx.xx.co.jp/SamlAuthTest</saml:Issuer><samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" /></samlp:AuthnRequest>
※Deflateエンコード→Base64エンコード→URLエンコードの順にエンコードしているのは、下記のページの「2. 認証要求メッセージをIdPに送る」を参考にしました。
【サイボウズエンジニアのブログ】SAML認証ができるまで
###補足情報(言語/FW/ツール等のバージョンなど)
言語:C#
FW:.NET Framework 4.5.1
開発環境:Visual Studio 2015
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。