SSO Complete Example in PHP
<html><body>
<script>
<?php
if (!$_REQUEST['logoff']) {
$profile = array(
'appId' => '123',
'userId' => '234',
'profile' => array(
'email' => 'test@example.com',
'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>