Socialid.login.init

From Social ID Developers
Revision as of 18:22, 28 January 2019 by Renato.neves (Talk | contribs)
Jump to: navigation, search

Contents

Description

Initializes the API to be used by a Social Login application. It's required to call this function to unlock the other Social Login APIs.

This function takes two important options: loginType and connectType. These options control how the Social Login flow is executed in the browser.

You can configure the loginType with one of the following values:

  • event: the Social Login is performed in a popup and all the steps generate Javascript events. The browser is not redirect to any location, you should handle the login success through socialid.events.onLoginSuccess.
  • callback: the Social Login is performed in a popup and at the end of the process the web page is redirected to the callback url configured in the Social Login dashboard. Intermediate login events are generated.
  • redirect: the Social Login is performed via redirects in the following order: website > socialid > social network > socialid > website callback. Popup is not used in this case. This option is useful for places where the browser is limited and cannot use popups.

You can configure the connectType with one of the following values:

  • event: the Social Connect is performed in a popup and all the steps generate Javascript events. The browser is not redirect to any location, you should handle the connect success through socialid.events.onConnectSuccess.
  • redirect: the Social Connect is performed via redirects in the following order: website > socialid > social network > socialid > website callback. Popup is not used in this case. This option is useful for places where the browser is limited and cannot use popups.

The callback url used in the "callback" and "redirect" types can be customized per request using the "loginRedirectURI" and "connectRedirectURI" options. You can also use the "redirectURI" option to set both URIs to the same value.

Usage

 socialid.login.init(appId, options)

Parameters

appId required The identifier number of the Social Login application.
options optional A Javascript object containing additional parameters.
loginType optional Define how the Social Login will be performed in the browser (see the description above). Can be "callback", "event" or "redirect". Default: "event".
connectType optional Define how the Social Connect will be performed in the browser (see the description above). Can be "event" or "redirect". Default: "event".
sessionType optional Define how the User's Session creation will be performed in the browser (see the description above). Can be "callback", "event" or "redirect". Default: "event".
loginRedirectURI optional Define the callback url that must be called after the user logs in. Applied only to loginType "callback" or "redirect". If no loginRedirectURI is defined, the redirectURI parameter is used. If no redirectUR is defined, the default callback configured in the Social Login is used. The loginRedirectURI domain must be allowed in the Social Login domains whitelist.
connectRedirectURI optional Define the callback url that must be called after the user connects. Applied only to connectType "redirect". If no connectRedirectURI is defined, the redirectURI parameter is used. If no redirectUR is defined, the default callback configured in the Social Login is used. The connectRedirectURI domain must be allowed in the Social Login domains whitelist.
sessionRedirectURI optional Define the callback url that must be called after the user's session is created. Applied only to sessionType "redirect". If no sessionRedirectURI is defined, the redirectURI parameter is used. If no redirectUR is defined, the default callback configured in the Social Login is used. The sessionRedirectURI domain must be allowed in the Social Login domains whitelist.
redirectURI optional Default callback url that must be called after the user logs in, connects or a session is created. The redirectURI domain must be allowed in the Social Login domains whitelist.
scope optional Define custom scopes for OAuth2 providers when the user logs in. Must be an object mapped by provider name, containing the scopes in a comma separated format. Example: {"facebook": "email,user_likes"}
errorRedirect optional Whether to redirect the user to the callback url when an error occurs. Applied only to loginType/connectType/sessionType "redirect". Default: false

Example

This example initializes the Social Login API to be used by the application with id "1" and defines the Social Login flow to generate Javascript events to handle the login responses, without redirects to the callback_url configured in the Social Login dashboard:

 socialid.login.init(1, {loginType: "event", connectType: "event"});

The following example initializes the Social Login API to be used by the application with id "567" and defines the Social Login flow to redirect to the "http://example.com/social_login" (the example.com domain must be white labeled) callback url after the user complete the social login:

 socialid.login.init(567, {loginType: "redirect", connectType: "redirect", "redirectURI": "http://example.com/social_login"});

The following example initializes the Social Login API to be used by the application with id "982" and defines a custom OAuth2 scope for the Facebook provider when the user logs in:

 socialid.login.init(982, {loginType: "event", connectType: "event", scope: {facebook: "email,user_likes"}});

You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox