Skip to content

Instantly share code, notes, and snippets.

@genee19
Forked from qetzal/gist:1118615
Created September 1, 2011 12:07
Show Gist options
  • Select an option

  • Save genee19/1186041 to your computer and use it in GitHub Desktop.

Select an option

Save genee19/1186041 to your computer and use it in GitHub Desktop.
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>
@genee19

genee19 commented Sep 1, 2011

Copy link
Copy Markdown
Author

See line 32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment