Social login

Social login can be your application’s primary or alternative authentication method.

If the user’s first login is via a social network, a new account is created automatically.

If you use social login as an alternative authentication method, the social network account automatically links to an existing user account if the following conditions are met:

  • A user who signed up with a username/email address and password logged into your application via a social network account.
  • A social network returns an email address.
  • User email address in a social network is the same as the email address used for sign-up in your application.

How-tos

Learn about advanced setups from our how-tos.

How to set up social login on Android devices

In mobile applications, you can implement social login by opening an authorization form inside the application. To do this, connect the native Xsolla SDK for Android to the Cocos Creator project. Using this library, you can open a social network authorization form in a custom WebView and receive a user token if login succeeds. In this case, the user does not need to leave the mobile application.

To add authorization through social networks in mobile applications:

  1. Connect native Xsolla SDK for Android to your project.
  2. Start authorization and processing of its results:

    1. Implement a UI for social login in your application (for example, the Sign in with Google button on the login page).
    2. In accordance with the logic of the application, implement a call of the authSocial native method. This method takes the name of the social network as a parameter.

Example of starting social login:

Copy
Full screen
Small screen

NativeUtil.authSocial(socialNetworkName);

    1. On the Cocos Creator side, subscribe to the successful authorization event. This event is generated at the scene level by native Activity that handles the authorization result. Once authorization is successful, call the handleSuccessfulSocialAuth handler method, which takes an object with the user’s token. This object can be used to further work with the Xsolla API.

Subscription example:

Copy
Full screen
Small screen

director.getScene().on(Events.SOCIAL_AUTH_SUCCESS, this.handleSuccessfulSocialAuth, this );

Note
From native scripts, the callback methods in Cocos Creator should be called from the game thread.

    1. Subscribe to login error and login cancellation events with a call to the necessary handler methods.

Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Hide

How to set up social login on iOS devices

In mobile applications, you can implement social login by opening an authorization form inside the application. To do this, you need to connect the native Xsolla SDK for iOS to the Cocos Creator project. Using this library, you can open a social network authorization form in a pop-up Safari tab and receive a user token if login succeeds. In this case, the user does not need to leave the mobile application.

To add authorization through social networks in the mobile application:

  1. Connect native Xsolla SDK for iOS to your project.
  2. Start authorization and processing of its results:

    1. Implement a UI for social login in your application (for example, the Sign in with Apple button on the login page).
    2. In accordance with the logic of the application, implement a call of the authSocial native method. This method takes the name of the social network as a parameter.

Example of starting social login:

Copy
Full screen
Small screen

NativeUtil.authSocial(socialNetworkName);

    1. On the Cocos Creator side, subscribe to the successful authorization event. This event is generated at the scene level by a snippet of TypeScript-code that handles the authorization result. Once authorization is successful, call the handleSuccessfulSocialAuth handler method, which takes an object with the user’s token. This object can be used to further work with the Xsolla API.

Subscription example:

Copy
Full screen
Small screen

director.getScene().on(Events.SOCIAL_AUTH_SUCCESS, this.handleSuccessfulSocialAuth, this );

Note
From native scripts, the callback methods in Cocos Creator should be called from the game thread.

    1. Subscribe to login error and login cancellation events with a call to the necessary handler methods.

Was this article helpful?
Thank you!
Is there anything we can improve? Message
We’re sorry to hear that
Please explain why this article wasn’t helpful to you. Message
Thank you for your feedback!
We’ll review your message and use it to help us improve your experience.
Hide
Last updated: September 9, 2022

Found a typo or other text error? Select the text and press Ctrl+Enter.

Report a problem
We always review our content. Your feedback helps us improve it.
Provide an email so we can follow up
Thank you for your feedback!