var token = "find token from somewhere";
//var token = rbv_api.getHTTPParameter("connection_token");
var siteDomain = 'https://XXXXX.api.oneall.com';
var publicKey = 'XXXXXXXXXXXX';
var privateKey = 'XXXXXXXXXXXXX';
var siteAuth = publicKey + ":" + privateKey;
var encodedSiteAuth = "XXXXXXXXXXXX";
//rbv_api.println(encodedSiteAuth);
var url = siteDomain + "/connections/" + token + ".json";
//var url = siteDomain + "/connections/a51cd9c5-df0c-467d-a5fc-deccfb883d38.json";
var data = null;
var method = "GET";
var contentType = "application/json; charset=UTF-8";
var header = { "Authorization" : "Basic " + encodedSiteAuth };
var request = rbv_api.sendJSONRequest(url, null, method, contentType, null, null, header);
//rbv_api.println(request);
var dj = JSON.parse(request);
//Extract data
var data = dj.response.result.data;
var userId;
var userToken;
var identityToken;
//Check for plugin
if (data.plugin.key === 'social_login'){
//Operation successful
if (data.plugin.data.status === 'success'){
//The user_token uniquely identifies the user
//that has connected with his social network account
userToken = data.user.user_token;
//The identity_token uniquely identifies the social network account
//that the user has used to connect with
identityToken = data.user.identity.identity_token;
// 1) Check if you have a userID for this token in your database
//userId = GetUserIdForUserToken(userToken);
// 1a) If the userID is empty then this is the first time that this user
// has connected with a social network account on your website
if (userId === null){
// 1a1) Create a new user account and store it in your database
// Optionally display a form to collect more data about the user.
//userId = {The ID of the user that you have created}
// 1a2) Attach the user_token to the userID of the created account.
//LinkUserTokenToUserId (userToken, userId);
}
// 1b) If you DO have an userID for the user_token then this user has
// already connected before
else{
// 1b1) The account already exists
}
// 2) You have either created a new user or read the details of an existing
// user from your database. In both cases you should now have a $user_id
// 2a) Create a Single Sign On session
// $sso_session_token = GenerateSSOSessionToken ($user_token, $identity_token);
// If you would like to use Single Sign on then you should now call our API
// to generate a new SSO Session: http://docs.oneall.com/api/resources/sso/
// 2b) Login this user
// You now need to login this user, exactly like you would login a user
// after a traditional (username/password) login (i.e. set cookies, setup
// the session) and forward him to another page (i.e. his account dashboard)
}
}
else if (data.plugin.key === 'social_link'){
//Operation successfull
if (data.plugin.data.status === 'success'){
//Identity linked
if (data.plugin.data.action === 'link_identity'){
//The identity has been linked to the user
userToken = data.user.user_token;
identityToken = data.user.identity.identity_token;
//Next Step:
// 1] Get _your_ userid from _your_ SESSION DATA
// 2] Check if the userid is linked to this user_token: GetUserIdForUserToken(user_token)
// 2.1] If not linked, tie the to this userid : LinkUserTokenToUserId(user_token, user_id)
// 3] Redirect the user to the account linking page
}
//Identity Unlinked
else if (data.plugin.data.action === 'unlink_identity'){
//The identity has been unlinked from the user
userToken = data.user.user_token;
identityToken = data.user.identity.identity_token;
//Next Step:
// 1] At your convenience
// 2] Redirect the user to the account linking page
}
}
}
var user_token = '';
var _oneall = _oneall || [];
_oneall.push(['social_link', 'set_providers', ['facebook', 'google', 'linkedin', 'twitter']]);
_oneall.push(['social_link', 'set_callback_uri', window.location.href]);
_oneall.push(['social_link', 'set_user_token', user_token]);
_oneall.push(['social_link', 'do_render_ui', 'oa_social_login_container']);
Please sign in to your OneAll account to ask a new question or to contribute to the discussions.
Please click on the link below to connect to the forum with your OneAll account.
Answers
have you already seen the events?
http://docs.oneall.com/api/javascript/library/events/#on_login_end_success
You do do something like this:
- Catch the connection_token by using an event
- Use an Ajax call to pass the connection_token to your script
- Your script extracts the data
Would that suit your needs?