2014-09-10 55 views
1

我有C#代碼產生SAML 2.0 AuthnRequest:爲什麼此SAML 2.0 AuthnRequest無效?

String requestXML = "<samlp:AuthnRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"https://saml.example.com/login\" Version=\"2.0\" IssueInstant=\"" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + "\" AssertionConsumerServiceIndex=\"0\"><saml:Issuer>https://saml.example.com/login</saml:Issuer><samlp:NameIDPolicy AllowCreate=\"true\" Format=\"urn:oasis:names:tc:SAML:2.0:nameid-format:transient\"/></samlp:AuthnRequest>"; 
String convertedRequestXML = System.Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(requestXML)); 
return Redirect("https://idp.ssocircle.com:443/sso/SSORedirect/metaAlias/ssocircle"+ "?SAMLRequest=" + convertedRequestXML + "&RelayState=" + HttpUtility.UrlEncode("/SamlLogin?ReturnUrl=" + returnurl)); 

用我的實際域名,而不是example.com。我與SP的元數據這樣

<md:EntityDescriptor 
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" 
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" 
entityID="https://saml.example.com/login"> 
<md:SPSSODescriptor 
    protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"> 
    <md:AssertionConsumerService index="0" 
     Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" 
     Location="https://saml.example.com/login" /> 
</md:SPSSODescriptor> 
<md:Organization> 
    <md:OrganizationName xml:lang="en"> 
     example 
    </md:OrganizationName> 
    <md:OrganizationDisplayName xml:lang="en"> 
     example 
    </md:OrganizationDisplayName> 
    <md:OrganizationURL xml:lang="en"> 
     http://www.example.com/ 
    </md:OrganizationURL> 
</md:Organization> 

此設置上https://ssocircle.com/但是,頁面與回報:

Error occurred 
Reason: The SAML Request is invalid. 

而且幫倒忙,沒有其他的錯誤。我也試着用https://openidp.feide.no來設置它,但是隻返回了一個500頁服務器錯誤的空白頁面。

我的GET字符串出來作爲

https://idp.ssocircle.com/sso/SSORedirect/metaAlias/ssocircle?SAMLRequest=PHNhbWxwOkF1dGhuUmVxdWVzdCB4bWxuczpzYW1scD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOnByb3RvY29sIiB4bWxuczpzYW1sPSJ1cm46b2FzaXM6bmFtZXM6dGM6U0FNTDoyLjA6YXNzZXJ0aW9uIiBJRD0iaHR0cHM6Ly9zYW1sLmV4YW1wbGUuY29tL2xvZ2luIiBWZXJzaW9uPSIyLjAiIElzc3VlSW5zdGFudD0iMjAxNC0wOS0xMVQwOTozMTo1NyIgQXNzZXJ0aW9uQ29uc3VtZXJTZXJ2aWNlSW5kZXg9IjAiPjxzYW1sOklzc3Vlcj5odHRwczovL3NhbWwuZXhhbXBsZS5jb20vbG9naW48L3NhbWw6SXNzdWVyPjxzYW1scDpOYW1lSURQb2xpY3kgQWxsb3dDcmVhdGU9InRydWUiIEZvcm1hdD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOm5hbWVpZC1mb3JtYXQ6dHJhbnNpZW50Ii8+PC9zYW1scDpBdXRoblJlcXVlc3Q+&RelayState=%2fSamlLogin%3fReturnUrl%3d31lOpEvtWshJNDa314yOgw%3d%3d 

https://idp.ssocircle.com/sso/toolbox/samlDecode.jsp是 '無法解碼' 和https://rnd.feide.no/simplesaml/module.php/saml2debug/debug.php出來與

<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="https://saml.example.com/login" Version="2.0" IssueInstant="2014-09-11T09:31:57" AssertionConsumerServiceIndex="0"><saml:Issuer>https://saml.example.com/login</saml:Issuer><samlp:NameIDPolicy AllowCreate="true" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient"/��[[�]]��\]Y\� 

我自己也嘗試了類似的結果

String convertedRequestXML = System.Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(requestXML)); 

我的問題是 1)我的SAML認證nRequest實際上有效嗎? 2)我的編碼方法是否正確? 3)有沒有更好的工具可以用來調試呢?當出現錯誤時,這些站點不會發出任何有用(或任何)錯誤消息

+0

你可以嘗試啓用System.Net跟蹤一個解釋。它可能會向您顯示有關傳出請求及其相關響應的更多信息。有關如何執行此操作的詳細信息,請參見[MSDN](http://msdn.microsoft.com/zh-cn/library/ty48b824(v = vs.110).aspx)。 – 2014-09-10 21:50:46

回答

6

Base64對請求進行編碼是不夠的,您還需要執行一些名爲deflating的操作。 閱讀HTTP redirect binding的章節。

有關於如何defalte在C#here

+0

謝謝Stefan,這是問題所在。 我使用的代碼來自http://stackoverflow.com/questions/12090403/how-do-i-correctly-prepare-an-http-redirect-binding-saml-request-using-c-sharp – 2014-09-12 01:59:07