Socialid.login.startConnect
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 Social 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
- socialid.events.onDisconnectSuccess
- socialid.events.onDisconnectError
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 there is a user already logged in the current session, the new credential is added to the user account and the user is redirected via HTTP POST to the redirect URI. The connection_id is passed along as a POST parameter.
- if there is no user logged in the current session, an error is displayed to the user.
Usage
socialid.login.startConnect(provider, options)
Parameters
provider | required | Determines which provider will be used in the connect process. Can be "facebook", "twitter", "linkedin" or "gplus". | options | optional | A Javascript object containing additional parameters. | redirectURI | optional | Overrides connectRedirectURI parameter | scope | optional | Overrides scope 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