Get Details about the Logged-in User
This article is about implementing SSO for Emplifi Ratings & Reviews widgets. For implementing SSO for the Emplifi platform, see Single Sign-on (SSO).
To complete this step, you'll fill out the loggedInDataFn
to get details about the logged-in user. When a user comes from an email, we use this function to make sure the user who came from the email is the same as the one who is logged in (if anyone is logged in at all).
If your site uses profile attributes, you can pass profile attributes for the user, which allows us to pre-populate the review form with the user's data.
Steps:
Familiarize yourself with the function reference for this step, which covers the
loggedInDataFn
andloggedInDataFnDone
functions.Inside the
loggedInDataFn
function, add code to check the user's logged-in status.If the user is logged in, generate the
loggedInData
, which is a JWT token you'll need to compute on the server side using your site's authKey. The authKey is available in your site's settings area.For details on the contents of the
loggedInData
, see the function reference forloggedInDataFnDone
.If the user is not logged in, the value of
loggedInData
should benull
.From the PDP, make a callback to the
loggedInDataFnDone
function with theloggedInData
.
Confirm that if the user is not logged in, the value ofloggedInData
isnull
.
The callback looks like this:CODETurnToCmd('loggedInDataFnDone', { context: contextObj, loggedInData: data });
When you're done with this step, the loggedInDataFnDone
function might be structured something like this:
var turnToConfig = {
...
sso: {
loggedInDataFn: function(contextObj){
if (isUserLoggedIn) {
// call an endpoint on your site that will provide the logged-in data
$.get( "user/sso/loggedInData", function( data ) {
// callback to Emplifi with result
TurnToCmd('loggedInDataFnDone', { context: contextObj, loggedInData: data });
});
} else {
// if the user is not logged in, there still needs to be a call back to Emplifi.
// in this case the loggedInData should be "null".
TurnToCmd('loggedInDataFnDone', { context: contextObj, loggedInData: null });
}
},
}
}
Examples and function reference
loggedInData generation example
Here is an example implementation of a server-side call to retrieve user data and generate the JWT loggedInData
. The key used in the example is aaa-aaa
. In a real implementation, it would be your site's authKey. This example is in PHP, but you are free to use Java or C# or whatever backend language your site uses on the server side.
LOGGEDINDATAFN(CONTEXTOBJ) function
This function is called by Emplifi code to retrieve details about a user who is currently logged in on your site. The operation is handled asynchronously, so this function does not have a return value. When a result is ready, your code makes a callback to the loggedInDataFnDone
function.
LOGGEDINDATAFNDONE function
This function is called by your code when user data for the currently logged-in user has been retrieved. This data can also pre-populate the user's profile data in a review form. The function is provided for your use via the TurnToCmd
object.