Socialid.login.extendCredentials

From Social ID Developers
Jump to: navigation, search

Contents

Description

API to extend a short lived token for a long lived one.

For now only the Facebook provider is supported. To get the access token you can use the Facebook API FB.getLoginStatus, available in Facebook SDK for JavaScript.

A common use case of this API is to integrate with any existing solution that uses the Facebook Javascript SDK.

Usage

 socialid.login.extendCredentials(provider, token, handler)

Parameters

provider required Login provider (social network). For now only "facebook" is supported.
token required User access token in the social network.
handler optional Callback function to handle the API response.

API Response

data In case of success, it'll be a Javascript object containing a credential object with the long lived access token.
status The API response status. Can be "success", if the token has been extended successfully, "not_found", if there is no Social Login application found, "forbidden", if the extension has not been authorized, "not_implemented", if the provider is not supported, or "internal_server_error", If some unknown error occurs.

Example

Extend a Facebook access token:

 var handler = function(response) {
    if (response.status == "success") {
       alert("Token extended successfully!");
       alert(response.data.facebook_credential.access_token);
    } else {
       alert("Could not extend token.");
    }
 }
 var appId = 1;
 socialid.login.init(appId);
 FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
       // the user is logged in and has authenticated your
       // app, and response.authResponse supplies
       // the user's ID, a valid access token, a signed
       // request, and the time the access token 
       // and signed request each expire
       var uid = response.authResponse.userID;
       var accessToken = response.authResponse.accessToken;
       socialid.login.extendCredentials('facebook', accessToken, handler);
    } else if (response.status === 'not_authorized') {
      // the user is logged in to Facebook, 
      // but has not authenticated your app
    } else {
      // the user isn't logged in to Facebook.
    }
 });

Example of "data" object:

 data = {
   "facebook_credential": {
     "access_token": "EAABuc0JrQX0BAI3DSXuKzdsZAcg9NbZCnMrLQJkuAvJPBSG1Oikqzca6Q2LsA2CzP3ZAxwzTHIi1afpEg6xX3qb5CofdaVB8YwlTNiaPZCUIo6A2uWsZD"
   }
 }
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox