Socialid.login.startLogin
Contents |
Description
Starts the social login process for the given provider. Can open a popup dialog or redirect to the provider, depending on the loginType.
Event Login Type
When the loginType is set to "event", this method can trigger the following events:
- socialid.events.onLoginStart
- socialid.events.onLoginSuccess
- socialid.events.onLoginCancel
- socialid.events.onLoginError
Redirect Login Type
When the loginType is set to "redirect", the API works as follows:
- If no error occurs, the user is redirected via HTTP POST to the redirect URI after the login succeeds. The login_token is passed along as the token 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 loginRedirectURI 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. | blocked | This Marketing Account is not receiving new logins because it hit the maximum number of contacts for its plan. | 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. |
---|
Callback Login Type
When the loginType is set to "callback", the API opens a popup and behaves just like the "event" loginType until the end of the login process. All login events can also be generated. However, at the end of a successful login, the user is redirected to the redirect URI following the same flow described for the "redirect" loginType.
Usage
socialid.login.startLogin(provider, options)
Parameters
provider | required | Determines which provider will be used in the login process. Can be "facebook", "twitter", "linkedin", "gplus", "instagram" or "apple". | options | optional | A Javascript object containing additional parameters. | redirectURI | optional | Overrides loginRedirectURI 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_login" button:
socialid.login.init(1, {loginType: "event"}); facebook_button = document.getElementById("facebook_login"); facebook_button.onclick = function() { socialid.login.startLogin("facebook"); };
You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground