SSO PHP Example
# PHP example for SSO
# specify up the username, the SSO password, and the space name
$postData = "birst.username=<userName>&birst.ssopassword=<ssoPassword>&birst.spaceId=<spaceId>";
$redirectURLBase = "https://login.bws.birst.com";
$url = "https://login.bws.birst.com/TokenGenerator.aspx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'header_callback');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
# get the secure token
$result = curl_exec($ch);
$response = curl_getinfo($ch);
curl_close($ch);
# use the secure token in an IFRAME request
$url = $redirectURLBase . "/SSO.aspx?birst.embedded=true&birst.hide&DashboardNavigation=true&birst.module=dashboard&birst.ssoToken=".$result;
print_r("<IFRAME SRC=".$url." WIDTH=800 HEIGHT=800></IFRAME>");
# called for each header, must return the number of characters processed, look for BirstURL: header
function header_callback($ch, $header_line)
{
global $redirectURLBase;
if (startsWith($header_line, "BirstURL: ")) # get the redirection URL
{
$redirectURLBase = rtrim(substr($header_line, strlen("BirstURL: ")));
}
return (strlen($header_line));
}
# grabbed from the web (overkill for here) - http://stackoverflow.com/questions/834303/php-startswith-and-endswith-functions
function startsWith($haystack,$needle,$case=true)
{
if($case) {return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
}