Socialid.login.startConnect
Ivan.filho (Talk | contribs) (→Parameters) |
|||
Line 3: | Line 3: | ||
Starts the social connect process for the given provider to connect a new provider credential in the current login session. Can open a popup dialog or redirect to the provider, depending on the [[socialid.login.init|connectType]]. | Starts the social connect process for the given provider to connect a new provider credential in the current login session. Can open a popup dialog or redirect to the provider, depending on the [[socialid.login.init|connectType]]. | ||
− | This process allows to add credentials from different social networks to the same | + | This process allows to add credentials from different social networks to the same Login User. For example, a user can log in with its Facebook and add its Twitter credential, so the next time this user can choose to log in with its Facebook or Twitter account and be referenced as the same user by the website integrating with the Social Login platform. |
==== Event Connect Type ==== | ==== Event Connect Type ==== |
Latest revision as of 17:02, 30 December 2021
Contents |
Description
Starts the social connect process for the given provider to connect a new provider credential in the current login session. Can open a popup dialog or redirect to the provider, depending on the connectType.
This process allows to add credentials from different social networks to the same Login User. For example, a user can log in with its Facebook and add its Twitter credential, so the next time this user can choose to log in with its Facebook or Twitter account and be referenced as the same user by the website integrating with the Social Login platform.
Event Connect Type
When the connectType is set to "event", this API can trigger the following events:
- socialid.events.onConnectStart
- socialid.events.onConnectSuccess
- socialid.events.onConnectCancel
- socialid.events.onConnectError
- socialid.events.onLoginSuccess
The API works as follows:
- if there is a user already logged in the current session, the new credential is added to the user account and the event socialid.events.onConnectSuccess is triggered.
- if there is no user logged in the current session, a new login is created (same behavior as the startLogin) and the event socialid.events.onLoginSuccess is triggered.
In summary, it's important to handle these two events. In case of socialid.events.onLoginSuccess it's important to check the login token via server-side to certificate that the user logged in is the same associated to the current website session.
Redirect Connect Type
When the connectType is set to "redirect", the API works as follows:
- If no error occurs, the new credential is added to the user account and the user is redirected via HTTP POST to the connectRedirectURI. The connection_id is passed along as the connection_id POST parameter.
- In case of error, the errorRedirect flag controls the flow. If set to false, an error message is displayed to the user. If set to true, the user is redirected to the connectRedirectURI via HTTP GET with the following query parameters:
error | An error code as defined in the OAuth2 specs. Possible values are: | unauthorized_client | The client is not authorized. | access_denied | The resource owner or authorization server denied the request. | server_error | The authorization server encountered an unexpected condition that prevented it from fulfilling the request. | error_code | A custom error code with more details about the error. Possible values are: | unauthorized | It wasn't possible to get the access token for the user because the login code expired or the application credentials are invalid. | not_found | The user was not found. | conflict | This credential is already associated with another user. In this case, disconnect the other user's credential to allow the connection for the current user. | user_inactive | The user is inactive. See: PUT login/users/:user_id/activate | internal_server_error | An unknown error occurred. | error_description | A user friendly message describing the error. |
---|
Usage
socialid.login.startConnect(provider, options)
Parameters
provider | required | Determines which provider will be used in the connect process. Can be "facebook", "twitter", "linkedin", "gplus", "instagram" or "apple". | options | optional | A Javascript object containing additional parameters. | redirectURI | optional | Overrides connectRedirectURI parameter | scope | optional | Overrides scope parameter | errorRedirect | optional | Overrides errorRedirect parameter |
---|
Example
It opens a popup starting the login dialog with Facebook when the user clicks on the "facebook_connect" button:
socialid.login.init(1, {connectType: "event"}); facebook_button = document.getElementById("facebook_connect"); facebook_button.onclick = function() { socialid.login.startConnect("facebook"); };
You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground