Socialid.login.startSession
Contents |
Description
Creates the user's session given a connection_id. Can open a popup dialog or redirect to the Social-ID Platform, depending on the sessionType.
Event Session Type
When the sessionType is set to "event", this method can trigger the following events:
Redirect Session Type
When the sessionType 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 session creation succeeds. 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 sessionRedirectURI 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: | not_found | The connection identifier was not found. | internal_server_error | An unknown error occurred. | error_description | A user friendly message describing the error. |
---|
Callback Session Type
When the sessionType is set to "callback", the API opens a popup and behaves just like the "event" sessionType until the end of the session creation process. All session events can also be generated. However, at the end of a successful session creation, the user is redirected to the redirect URI following the same flow described for the "redirect" sessionType.
Usage
socialid.login.startSession(connection_id, options)
Parameters
connection_id | required | User connection identifier. | options | optional | A Javascript object containing additional parameters. | redirectURI | optional | Overrides sessionRedirectURI parameter | errorRedirect | optional | Overrides errorRedirect parameter |
---|
Example
It redirects the browser to the Social-ID Platform, that will validate the connectionId, create the user's session and redirect back to "http://example.com/callback":
var appId = 1, connectionId = '1234567890'; socialid.login.init(appId, {sessionType: "redirect", sessionRedirectURI: "http://example.com/callback"}); socialid.login.startSession(connectionId);
You can test this parameters in our playground: https://sid-examples.herokuapp.com/social_logins/playground