Socialid.login.loginCredentials

From Social ID Developers
Revision as of 19:16, 3 November 2014 by Renato.neves (Talk | contribs)
Jump to: navigation, search

Contents

Description

API to automatically log an user given its social networks credentials.

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 para Javascript.

A common use case of this API is to integrate with any existing solution that uses the Facebook Javascript SDK. This way it's simple to feed the Social Login (and the Marketing Database) with the user's social information.

This method can trigger the following events:

Usage

 socialid.login.loginCredentials(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 Em caso de sucesso, será um objeto contendo as informações do evento socialid.events.onLoginSuccess. Em caso de erro de login, será um objeto com informações do evento socialid.events.onLoginError. É importante notar que estes eventos também serão disparados, ou seja, é recomendado implementar handlers para estes eventos em vez de tratar a resposta desta API.
status O status da execução da chamada da API. Pode ser "success", se o usuário foi logado com sucesso, "not_found", caso não exista a aplicação de Social Login, "forbidden", caso o login não tenha sido autorizado, "not_implemented", caso o provider não seja suportado, ou "internal_server_error", caso algum erro desconhecido aconteça.

Example

Loga um usuário na sessão atual dado seu access token do Facebook:

 var handler = function(response) {
    if (response.status == "success") {
       alert("Usuário logado com sucesso");
    } else {
       alert("Não foi possível logar o usuário.");
    }
 }
 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.loginCredentials('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 = {
   event: "onLoginSuccess",
   token: "13d7555531d285adc34e21e7a9c583967c7a85507deee61fb6f1eeffc656409w",
   callback_url: "https://sid-examples.herokuapp.com/social_logins",
   provider: "facebook"
 }

You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox