This document explains sample JavaScript code snippets for Base64 Authentication in separate sections below.

Authentication process 

The authentication process is given below:

  • If a user is already logged in to merchant’s website, we do not want the user to go through the authentication process again for ShopSocially’s Loyalty Program. We would seamlessly want the merchant user to become ShopSocially’s loyalty program user. To achieve this purpose with just JavaScript, we have Base64 Authentication.
  • In Base64 Authentication, you would need to pass us logged in user’s details by making JavaScript call. 
  • ShopSocially will then read this user information and create a session for the user and log the user in.

Logout process

The logout process is given below:
  • Along with the seamless authentication of a merchant’s user into ShopSocially’s loyalty program, we would also need seamless logout functionality so that when a user is logged out of merchant’s website, he would get logged out of ShopSocially as well. 
  • For this purpose, ShopSocially provides a javascript logout functionality. 
  • Pseudo – code javascript snippets for handling both authentication and logout scenarios are given below. These are ready to use snippets. You would just need to insert the logic of determining whether a user is logged in to merchant website or not and the logic to pass the user information when you make a call to ss_mi.authenticate_loyalty_user(user_info)

Javascript pseudo-codes for Authentication and Logout
The details of the Javascript pseudo-codes for Authentication and Logout, and sample code are given below:
  • This code can go on all the pages that are going to load the ShopSocially all.js javascript. 
  • This pseudo code contains both the javascript code for authentication and also handles the logout functionality. 
  • Please note that this is just a sample pseudo code and the developer implementing this will need to make necessary amendments wherever suggested (in italics)

<script language="javascript" type="text/javascript">
    var user_info = {};
    var is_user_logged_into_merchant_website = <true or false depending on whether a user is logged into merchant     site>;
    user_info[‘first_name’] = <first name of the logged in user>;
    user_info[‘last_name’] = <last name of the logged in user>;
    user_info[‘uid’] = <set unique identifier of the logged in user here. This UID should uniquely identify a user at
    merchant’s end throughout the user’s lifetime>;
    user_info[‘email’] = <Email address of the logged in user>;
    /*define the function*/
    authenticate_ss_loyalty_user = function () {
        if(typeof ss_mi === 'undefined'){
            return setTimeout(authenticate_ss_loyalty_user, 1000);
        }else if (!ss_mi.is_loyalty_user_logged_in()){

    /* Call the above defined function if user is logged into merchant website */
    if(is_user_logged_into_merchant_website) {

    /* loyalty authentication success and failure handlers. To override ShopSocially’s default success and failure 
    handlers these two have to be present */
    window.ssmi_authenticate_loyalty_user_success_handler = function(){
    window.ssmi_authenticate_loyalty_user_failure_handler = function() {
//Define Logout function
check_and_logout_ss_user = function () {
var is_user_logged_in_to_merchant_website = <true or false depending on whether a user is logged into merhant’s site>
    if(!is_user_logged_in_to_merchant_website) {
    if(typeof ss_mi === 'undefined'){
        return setTimeout(check_and_logout_ss_user, 1000);
    } else {
      if(!ss_mi.partner_id) {
        return setTimeout(check_and_logout_ss_user,1000);
        } else {
          var isloyaltyUserLoggedIn = ss_mi.is_loyalty_user_logged_in();
          if(isloyaltyUserLoggedIn == true){

//Call the function

// The blank functions need to be present on the page so that ShopSocially default handlers are overriden
window.ssmi_logout_loyalty_user_success_handler = function() {
            //blank function
window.ssmi_logout_loyalty_user_failure_handler = function() {
            //blank function