Socialid.login.loginUserToken

From Social ID Developers
Jump to: navigation, search

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