Socialid.login.loginUserToken

From Social ID Developers
(Difference between revisions)
Jump to: navigation, search
(Parameters)
(Example)
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
 
== Description ==
 
== Description ==
  
Chama a API para logar automaticamente um usuário dado seu user_id e user_token.
+
API to automatically log an user given its user_token.
  
O user_id e user_token podem ser obtidos a partir da API [[GET login/info]] ou [[GET login/users/:user_id]].
+
The userId and userToken can be retrieved from the RESTful APIs [[GET login/info]] or [[GET login/users/:user_id]].
  
Um caso de uso desta API é para quando a sessão (cookie) do usuário no Social Login tenha expirado ou sido apagada e se queira logar automaticamente um usuário já identificado (via login tradicional ou outro meio).
+
A common use case for this API is when the user session (cookie) in the Social Login has been expired or erased and you want to log the user automatically given you already identified him before via traditional login, for example.
 +
 
 +
<span style="color: red">Important:</span> see [[Social Login Tokens]] for detailed information about the tokens used by the Social Login and best security practices.
  
 
== Usage ==
 
== Usage ==
Line 15: Line 17:
 
{|
 
{|
 
! align="left" width="200px" | userId
 
! align="left" width="200px" | userId
| width="200px" | obrigatório
+
| width="200px" | required
| Id do usuário.
+
| User identifier.
 
|+
 
|+
 
! align="left" width="200px" | userToken
 
! align="left" width="200px" | userToken
| width="200px" | obrigatório
+
| width="200px" | required
| Token do usuário.
+
| User token.
 
|+
 
|+
 
! align="left" width="200px" | handler
 
! align="left" width="200px" | handler
| width="200px" | opcional
+
| width="200px" | optional
| Especifica uma função de callback para tratar a resposta da API.
+
| Callback function to handle the API response.
 
|}
 
|}
  
Line 31: Line 33:
 
{|
 
{|
 
! align="left" width="200px" | data
 
! align="left" width="200px" | data
| Em caso de sucesso, será um objeto contendo o connection_id gerado para o usuário.
+
| In case of success, it will be a Javascript object containing the connection_id and login_token generated for the user.
 
|+
 
|+
 
! align="left" width="200px" | status
 
! align="left" width="200px" | status
| O status da execução da chamada da API. Pode ser "success", se o usuário foi logado com sucesso, ou "not_found", caso não exista a combinação user_id e user_token para o Social Login.
+
| The API response status. Can be '''success''', if the user has been logged in successfully, or '''not_found''', if there is no valid combination of the given userId and userToken.
 
|}
 
|}
  
 
== Example ==
 
== Example ==
  
Loga um usuário na sessão atual dado seu user_id e user_token:
+
Automatically logs an user given its user_id and user_token:
  
 
   var handler = function(response) {
 
   var handler = function(response) {
 
     if (response.status == "success") {
 
     if (response.status == "success") {
         alert("Usuário logado com sucesso");
+
         alert("You have been logged in successfully!");
 
     } else {
 
     } else {
         alert("User_id e user_token não conferem.");
+
         alert("userId and userToken are invalid.");
 
     }
 
     }
 
   }
 
   }
Line 52: Line 54:
 
   socialid.login.loginUserToken(userId, userToken, handler);
 
   socialid.login.loginUserToken(userId, userToken, handler);
  
Exemplo de dados no objeto "data":
+
Example of "data" object:
  
 
   data = {
 
   data = {
     connection_id: "3875294927582875"
+
     connection_id: "a9f0c3ba3043d7a27a9a17e6911c258fca7b51b4701b7f797797f76768baa236",
 +
    login_token: "aa32e1876af589ceddee2cf2288864965b66e18fd1c26923cd1aee3de0a5debc"
 
   }
 
   }
  
Teste as APIs em nosso playground: https://sid-examples.herokuapp.com/social_logins/playground
+
You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground

Latest revision as of 12:43, 11 December 2015

Contents

Description

API to automatically log an user given its user_token.

The userId and userToken can be retrieved from the RESTful APIs GET login/info or GET login/users/:user_id.

A common use case for this API is when the user session (cookie) in the Social Login has been expired or erased and you want to log the user automatically given you already identified him before via traditional login, for example.

Important: see Social Login Tokens for detailed information about the tokens used by the Social Login and best security practices.

Usage

 socialid.login.loginUserToken(userId, userToken, handler)

Parameters

userId required User identifier.
userToken required User token.
handler optional Callback function to handle the API response.

API Response

data In case of success, it will be a Javascript object containing the connection_id and login_token generated for the user.
status The API response status. Can be success, if the user has been logged in successfully, or not_found, if there is no valid combination of the given userId and userToken.

Example

Automatically logs an user given its user_id and user_token:

 var handler = function(response) {
    if (response.status == "success") {
       alert("You have been logged in successfully!");
    } else {
       alert("userId and userToken are invalid.");
    }
 }
 var appId = 1, userId = 34, userToken = '1234567890';
 socialid.login.init(appId);
 socialid.login.loginUserToken(userId, userToken, handler);

Example of "data" object:

 data = {
   connection_id: "a9f0c3ba3043d7a27a9a17e6911c258fca7b51b4701b7f797797f76768baa236",
   login_token: "aa32e1876af589ceddee2cf2288864965b66e18fd1c26923cd1aee3de0a5debc"
 }

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

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox