CorePHP - SAMLSignOn failed: Failed to convert the base-64 encoded string into XML

507 views Asked by At

I have setup Identity Provider for SAML assertion using corePHP. I am using curl to send assertion request to Service Provider.

My identity provider is on core php using curl.

Service Provider is made using componentspace saml2.0 in asp.net

Here is my code:

$url = "https://sp.name.com/sso/saml";

$filename = "saml1.xml";
$read = fopen($filename, "r");
$XML = fread($read, filesize($filename));
fclose($read);

$XML_utf8 = utf8_encode($XML);
$XML64 = base64_encode($XML_utf8);

$data = "SAMLResponse=".$XML64."&RelayState=https://sp.name.com/sso/saml";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);

When I run this script on my service provider following errors messages generate:

SAMLSignOn failed: Failed to convert the base-64 encoded string into XML.
[Exception: SAMLSignOn failed: Failed to convert the base-64 encoded string into XML.]
[SAMLSerializationException: Failed to convert the base-64 encoded string into XML.]

I have already spent long time on this issue.

1

There are 1 answers

0
Jitender Singla On BEST ANSWER

There was issues with the certificate mismatch and saml assertion format. So we switched to asp.net and stopped using PHP for the task. Now we are using COMPONENTSPACE SAML2.0 library in asp.net

Question is: How do we manage to run php code with asp.net

ANS: We send an api request to asp.net code with login credentials and asp.net calls service provider and returns us the redirect url.

Hope this may help