Progress will discontinue Telerik Platform on May 10th, 2018. Learn more

Integrating Social Login

Integrating Social Login

The Backend Services JavaScript SDK provides these methods for registering and authenticating users coming from social authentication providers such as Facebook, Google, and Microsoft Account:

Prerequisites

  • Ensure that you have enabled the provider that you want to use.
  • Obtain an OAuth token for the user. Refer to the social authentication provider's official documentation for more information:

Registration/Login

You register or log in a social user by invoking the respective member of the Authentication.loginWith<Provider>() method family that belong to the predefined collection object for Users (see the table). The first invocation of the method for a user creates a new user account. Subsequent invocations log in the user to Telerik Platform. See Social Authentication for more information.

Method Name Use for Provider
loginWithFacebook() Facebook
loginWithGoogle() Google
loginWithLiveId() Microsoft Account
loginWithTwitter() Twitter

All methods take as argument the OAuth token that you obtained from the social authentication provider. For Twitter, add the access token secret as well. For example:

  • For loginWithFacebook(), loginWithGoogle(), and loginWithLiveId():

    var el = new Everlive('your-app-id');
    var accessToken = "Facebook access token";
    el.authentication.loginWithFacebook(accessToken,
        function (data) {
            alert(JSON.stringify(data));
        },
        function(error){
            alert(JSON.stringify(error));
        });
    

    Developers who have been using the Google Access Token (access_token) parameter to authenticate users are strongly advised to migrate to using the Google ID Token (id_token) parameter instead. Doing so significantly boosts your app security because Telerik Platform can verify the aud claim contained in the token. Note that you also need to enter a Client Id when enabling Google Login, otherwise Telerik Platform skips this verification.

  • For loginWithTwitter():

    var el = new Everlive('your-app-id');
    var accessToken = "Twitter access token";
    var accessTokenSecret = "Twitter access token secret";
    el.authentication.loginWithTwitter(accessToken, accessTokenSecret,
        function (data) {
            alert(JSON.stringify(data));
        },
        function(error){
            alert(JSON.stringify(error));
        });
    

On success, the method returns an object containing a Telerik Platform access token (not to be mistaken with the OAuth token) that can be used with further Backend Services JavaScript SDK operations. In that, the loginWith<Provider>() method behaves similarly to the login() method. If the user has already been registered, the object contains Id and CreatedAt fields in addition.

Linking with an OAuth Provider

You link a social user to an existing Telerik Platform user account using a member of the Users.linkProviderAccount() method family of the predefined collection object for Users. The next table lists all available methods:

Method Name Use for Provider
linkWithFacebook Facebook
linkWithGoogle Google
linkWithLiveID Microsoft Account
linkWithTwitter Microsoft Account

The methods take as argument the userId of the Telerik Platform user account that you want to link to, and the acquired OAuth token. For Twitter, add the access token secret as well. For example:

  • For linkWithFacebook(), linkWithGoogle(), and linkWithLiveID():

    var el = new Everlive('your-app-id');
    var userId = "item-id";
    var accessToken = "Facebook access token";
    el.Users.linkWithFacebook(userId, accessToken,
        function (data) {
            alert(JSON.stringify(data));
        },
        function(error){
            alert(JSON.stringify(error));
        });
    

    Developers who have been using the Google Access Token (access_token) parameter to authenticate users are strongly advised to migrate to using the Google ID Token (id_token) parameter instead. Doing so significantly boosts your app security because Telerik Platform can verify the aud claim contained in the token. Note that you also need to enter a Client Id when enabling Google Login, otherwise Telerik Platform skips this verification.

  • For linkWithTwitter():

    var el = new Everlive('your-app-id');
    var userId = "item-id";
    var accessToken = "Twitter access token";
    var accessTokenSecret = "Twitter access token secret";
    el.Users.linkWithTwitter(userId, accessToken, accessTokenSecret,
        function (data) {
            alert(JSON.stringify(data));
        },
        function(error){
            alert(JSON.stringify(error));
        });
    

To use these methods, you need to first log the user in or use MasterKey authentication.

If a Telerik Platform user account is already linked to a user from the specified social provider, the method returns an error. To link it to a new social user, first unlink it from the previous one and then reinvoke linkProviderAccount() with the new OAuth token.

Unlinking from an OAuth Provider

You unlink a social user from an existing Telerik Platform user account using a member of the Users.unlinkProviderAccount() method family of the predefined collection object for Users. The next table lists all available methods:

Method Name Use for Provider
unlinkFromFacebook Facebook
unlinkFromGoogle Google
unlinkFromLiveID Microsoft Account
unlinkFromTwitter Microsoft Account

The methods take as argument the userId() of the Telerik Platform user account that you want to unlink. For example:

```JavaScript
var el = new Everlive('your-app-id');
var userId = "item-id";
el.Users.unlinkFromFacebook(userId,
    function (data) {
        alert(JSON.stringify(data));
    },
    function(error){
        alert(JSON.stringify(error));
    });
```

If the user is not linked, you receive an error.

See Also

Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.