Socialid.login.loginCredentials
From Social ID Developers
(Difference between revisions)
Renato.neves (Talk | contribs) (→API Response) |
|||
(8 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
== Description == | == 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 [https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/ FB.getLoginStatus], available in [https://developers.facebook.com/docs/javascript Facebook SDK for 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: | |
* [[socialid.events.onLoginSuccess]] | * [[socialid.events.onLoginSuccess]] | ||
* [[socialid.events.onLoginError]] | * [[socialid.events.onLoginError]] | ||
Line 19: | Line 19: | ||
{| | {| | ||
! align="left" width="200px" | provider | ! align="left" width="200px" | provider | ||
− | | width="200px" | | + | | width="200px" | required |
− | | | + | | Login provider (social network). For now only "facebook" is supported. |
|+ | |+ | ||
! align="left" width="200px" | token | ! align="left" width="200px" | token | ||
− | | width="200px" | | + | | width="200px" | required |
− | | | + | | User access token in the social network. |
|+ | |+ | ||
! align="left" width="200px" | handler | ! align="left" width="200px" | handler | ||
− | | width="200px" | | + | | width="200px" | optional |
− | | | + | | Callback function to handle the API response. |
|} | |} | ||
Line 35: | Line 35: | ||
{| | {| | ||
! align="left" width="200px" | data | ! align="left" width="200px" | data | ||
− | | | + | | In case of success, it'll be a Javascript object containing the [[socialid.events.onLoginSuccess]] event data. In case of login error, it'll be a Javascript object containing the [[socialid.events.onLoginError]] event data. It is important to note that these events will also be fired, that is, it is recommended to implement handlers for these events instead of handle the response of this API. |
|+ | |+ | ||
! align="left" width="200px" | status | ! align="left" width="200px" | status | ||
− | | | + | | The API response status. Can be '''"success"''', if the user has been logged in successfully, '''"not_found"''', if there is no Social Login application found, '''"forbidden"''', if the login has not been authorized, '''"not_implemented"''', if the provider is not supported, or '''"internal_server_error"''', If some unknown error occurs. |
|} | |} | ||
== Example == | == Example == | ||
− | + | Automatically logs an user given its Facebook access token: | |
var handler = function(response) { | var handler = function(response) { | ||
if (response.status == "success") { | if (response.status == "success") { | ||
− | alert(" | + | alert("You have been logged in successfully!"); |
} else { | } else { | ||
− | alert(" | + | alert("Could not log you."); |
} | } | ||
} | } | ||
− | var appId = 1 | + | var appId = 1; |
socialid.login.init(appId); | 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 = { | data = { | ||
Line 65: | Line 82: | ||
} | } | ||
− | + | You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground |
Latest revision as of 20:21, 23 December 2016
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 for 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 | In case of success, it'll be a Javascript object containing the socialid.events.onLoginSuccess event data. In case of login error, it'll be a Javascript object containing the socialid.events.onLoginError event data. It is important to note that these events will also be fired, that is, it is recommended to implement handlers for these events instead of handle the response of this API. | status | The API response status. Can be "success", if the user has been logged in successfully, "not_found", if there is no Social Login application found, "forbidden", if the login has not been authorized, "not_implemented", if the provider is not supported, or "internal_server_error", If some unknown error occurs. |
---|
Example
Automatically logs an user given its Facebook access token:
var handler = function(response) { if (response.status == "success") { alert("You have been logged in successfully!"); } else { alert("Could not log you."); } } 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