The following guide discusses implementing a connection to a social network, when your site user is logged in with a different social network. This guide is intended for use for Gigya customers who do not use RaaS.
A social network connection is equivalent to an established session the current user has with a social network. A valid and active connection is required in order to perform social interaction using Gigya, such as sharing content and accessing the user's social graph.
From the user's point of view, connecting to a social network is similar to logging in, in that the user is required to provide their social network's credentials and authorize the site. However, connections are a separate concept.
The Distinction between Login and Adding Connection
Social login is the process of identifying a person and assigning an ID in a secure, reliable and repeatable way. It ensures the same person gets the same ID every time they are authenticated. This process is a discrete operation with a clear beginning and end. It only happens when the user logs in, and does not require any long-term interaction with the user or the social login providers beyond that point in time. The Gigya API calls related to social login are socialize.login, socialize.showLoginUI, socialize.logout, socialize.notifyLogin, and socialize.notifyRegistration.
Social connection is an established session with a social network, that may expire according to the social network's policy. A valid and active connection is required for the user to perform social interaction using Gigya, such as sharing content. The Gigya API calls for establishing connections are socialize.addConnection, socialize.showAddConnectionsUI and socialize.removeConnection (for terminating connections).
The process of logging in and of adding a connection is the same for the user. In both, the user is asked to log into a social network and authorize the site. The goal, however, is very different: only a login operation authenticates the user in a way that retrieves a persistent user ID.
When Should You Use the "Add Connection" API Methods?
The rule of thumb is to use it when:
- You want to add another connection to a user who is already logged in (even if that user used your own login system - as long as you called the socialize.notifyLogin API method).
- You want to provide social services in a section of your site that does not require login. If a user logs in, their connection will be imported automatically to the user's account.
Best Practice: Add Connections only after Logging in
We recommend adding the Add Connections plugin to your webpages only for when the current user is logged in. You can display the Add Connections plugin instead of the Login plugin after the user logs in. This provides the logged-in user with an option to add connections to multiple social networks in order to interact with additional friends. For more information, see Social Login - Best practice implementation.
Adding Connections Using Social Plugins
In addition to the Add Connections Plugin, the 'Adding Connection' operation may be initiated indirectly through the usage of one of the following plugins: Comments Plugin, Share Plugin (each of these plugins includes an inner 'Adding Connections' UI).
Implementation - Using the Add Connections Plugin
To integrate the Add Connections Plugin, we recommend following these steps:
- Add the Add Connections Plugin to your site. You can integrate the Add Connections functionality in any page that requires social connectivity. The easiest method is the Add Connections Plugin wizard, which lets you customize the plugin and displays a preview. Based on your modifications, the wizard generates code that you can insert into your application. Alternatively, you may design your own user interface and call the socialize.addConnection API method.
- When the Gigya authentication process completes, you will be notified with an onConnectionAdded event. To learn more about how to register and handle events generated by the Gigya service, refer to the Events page. The onConnectionAdded event data will be used in the next steps.
The user is now authenticated and connected to their social network.
Next you can do the following:
- The User Object that you receive from Gigya (with the onConnectionAdded event data), holds user information extracted from his social network profile. You can use the information that is relevant to your site.
- You can use the Gigya API to push/pull information to/from the social network: Share content, set status, get friends, send notifications, etc.