Socialid.login.startLogin

From Social ID Developers
Jump to: navigation, search

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:

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 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.

In case the connectionStorageType is set to cookie, at the redirect URI, the received Connection ID parameter, must be saved into a cookie with the same name given at connectionStorageOptions.

In case the connectionStorageType is set to localStorage, after the redirect URI, the received Connection ID parameter, must be saved as a local storage item with the same name given at connectionStorageOptions.

In case the connectionStorageType is set to sessionStorage, after the redirect URI, the received Connection ID parameter, must be saved as a session storage item with the same name given at connectionStorageOptions.

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

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox