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

Integrating Social Login

Integrating Social Login

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

Prerequisites

You can also use the RadCloudLogIn control from the Telerik UI for Windows Phone product line. It implements social login to Facebook, Microsoft Account, and Google. For details see its documentation page.

Registration/Login

You register or log in a social user by invoking the respective member of the LoginWith<Provider>() method family that belongs to the AuthenticationHandler class (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():

    public async Task LoginUser(EverliveApp app, string accessToken)
    {
        await app.WorkWith().Authentication().LoginWithFacebook(accessToken).ExecuteAsync();
    }
    

    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():

    public async Task LoginUser(EverliveApp app, string accessToken, string accessTokenSecret)
    {
        await app.WorkWith().Authentication().LoginWithTwitter(accessToken, accessTokenSecret).ExecuteAsync();
    }
    

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 .NET SDK operations. In that, the LoginWith<Provider>() method behaves similarly to the Login() method.

Linking with an OAuth Provider

You link a social user to an existing Telerik Platform user account using a member of the Link<Provider>Account() method family that belongs to the UsersHandler class. The next table lists all available methods:

Method Name Use for Provider
LinkFacebookAccount() Facebook
LinkGoogleAccount() Google
LinkLiveIdAccount() Microsoft Account
LinkTwitterAccount() 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 LinkFacebookAccount(), LinkGoogleAccount(), and LinkLiveIdAccount():

    public async Task LinkUser(EverliveApp app, Guid userId, string accessToken)
    {
        await app.WorkWith().Users().LinkFacebookAccount(userId, accessToken).ExecuteAsync();
    }
    

    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 LinkTwitterAccount():

    public async Task LinkUser(EverliveApp app, Guid userId, string accessToken, string accessTokenSecret)
    {
        await app.WorkWith().Users().LinkTwitterAccount(userId, accessToken, accessTokenSecret).ExecuteAsync();
    }
    

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 Link<Provider>Account() 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 Unlink<Provider>Account() method family that belongs to the UsersHandler class. The next table lists all available methods:

Method Name Use for Provider
UnlinkFacebookAccount() Facebook
UnlinkGoogleAccount() Google
UnlinkLiveIdAccount() Microsoft Account
UnlinkTwitterAccount() Twitter

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

public async Task UnlinkUser(EverliveApp app, Guid userId)
{
    await app.WorkWith().Users().UnlinkFacebookAccount(userId).ExecuteAsync();
}

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

See Also

Friends Sample App

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