-
-
Save genee19/1186041 to your computer and use it in GitHub Desktop.
SSO Complete Example in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><body> | |
<script> | |
<?php | |
if (!$_REQUEST['logoff']) { | |
$profile = array( | |
'appId' => '123', | |
'userId' => '234', | |
'profile' => array( | |
'email' => '[email protected]', | |
'billingPerson' => array( | |
'name' => 'Tester', | |
'companyName' => 'Company Name', | |
'street' => 'Street', | |
'city' => 'City', | |
'countryCode' => 'US', | |
'postalCode' => '10001', | |
'stateOrProvinceCode' => 'NY' | |
) | |
) | |
); | |
$message = json_encode($profile); | |
$message = base64_encode($message); | |
$timestamp = time(); | |
$hmac = hash_hmac('sha1', "$message $timestamp", "A1Lu8ANIhKD6"); | |
echo "var ecwid_sso_profile='$message $hmac $timestamp'"; | |
} else { | |
echo "var ecwid_sso_profile=''"; | |
} | |
?> | |
</script> | |
<script src="http://app.ecwid.com/script.js?1003"></script> | |
<div class="<?php if (!empty($message)) { echo 'logged-in'; } else { echo 'anonymous' }?>"> <!-- This <div> needs to be added with a class depending on the status of being logged in --> | |
<script> | |
xProductBrowser(); | |
function logout() { | |
window.Ecwid.OnAPILoaded.add(function() { | |
window.Ecwid.setSsoProfile(''); | |
}); | |
} | |
</script> | |
</div> | |
<a href="javascript: logout()">Log out</a> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See line 32