SDK pour Unity destinés aux entreprises / Connexion via les réseaux sociaux
  Retour à la documentation

SDK pour Unity destinés aux entreprises

Connexion via les réseaux sociaux

In your application, you can implement user authentication using their account in social networks. If the user’s first login is via a social network, a new account is created automatically. The user doesn’t need to enter a username, email address, or other data.

There are two ways to implement authentication through social networks:

  • Web-based authentication. In this case, the application opens a form in the browser to complete authentication via the selected social network. This option is suitable for both mobile and desktop applications.
  • Native authentication. In this case, authentication is performed via the social network application on the user’s device. This option is only suitable for mobile applications.

Note
To authenticate users of your iOS application using their Apple ID, Face ID, or Touch ID, implement web-based authentication. In this case, the SDK methods use native libraries for iOS.

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

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.
  • The user’s email address in a social network matches the email address used to sign up in your application.

You can also implement manual linking of a social network account.

Instructions

Learn about advanced setups from our how-tos.

Comment configurer l'authentification Web via les réseaux sociaux

SDK supports the following providers for social login:

  • Amazon
  • Apple
  • Baidu
  • Battle.net
  • Discord
  • Facebook
  • GitHub
  • Google
  • Kakao
  • LinkedIn
  • MSN
  • Mail.ru
  • Microsoft
  • Naver
  • Odnoklassniki
  • PayPal
  • QQ
  • Reddit
  • Steam
  • Twitch.tv
  • Twitter
  • VK
  • Vimeo
  • WeChat
  • Weibo
  • Xbox Live
  • Yahoo
  • Yandex
  • YouTube

To set up authentication through web services:

  1. In the application interface, add buttons for authentication via social networks.
  2. Set up social connections for a Login project in Publisher Account.
  3. Implement authentication logic on the application side.

Configurer les réseaux sociaux pour le projet de connexion dans le Compte éditeur Xsolla

Avis
In Publisher Account, ensure the Classic login and Social login option are selected for the Login project that you use in your application. You can change the login method later by clicking the Change Login method link. Previously saved settings will not be lost.
  1. Open your project in Publisher Account.
  2. In the side menu, сlick Login.
  3. Click Configure in the pane of a Login project.
  4. On the navigation page, go to the Authentication block and select the Social login section.
  1. Connect social networks that users can use to sign up and log into the application:
    • To connect a social network, click the ⚙ icon and select Connect.
    • To connect several social networks at once, select the required panes (their borders will turn green). Then, from the Manage drop-down menu, select Connect.
    • To connect all available social networks, click Select all. Then, from the Manage drop-down menu, select Connect.
Note
Xsolla’s Application ID and secret key are used for authentication by default. If your application is set up using a developer account of the social provider, you can specify your own Application ID and secret key. Detailed instructions for locating the Application ID and secret are available in the social network card settings in Publisher Account.

Intégration côté application

Implement the following logic when clicking the social login button:

  1. For desktop applications:
    1. Get the sign-up/login page URL using the GetSocialNetworkAuthUrl SDK method.
    2. Open the sign-up/login page in a browser using the BrowserHelper.Instance.InAppBrowser method.
    3. Subscribe to the URL change event. To do that, add the BrowserHelper.Instance.InAppBrowser.AddUrlChangeHandler(OnUrlChanged) callback.
    4. Track the page URL change after successful user authentication.
    5. Get the authentication code from the URL of the active page. You can use the ParseUtils.TryGetValueFromUrl() SDK helper method to do this.
    6. Exchange the authentication code for a token using the ExchangeCodeToToken SDK method and use it in requests to Xsolla servers.
Note

An example of the implementation of this logic is available in the Assets/Xsolla.Demo/Login/Scripts/Login/Auth/SocialAuth.cs script of the demo project.

Social login isn’t available for external browsers. The SDK contains a built-in browser developed by Xsolla for desktop applications. You can either use Xsolla’s built-in browser or a different built-in browsing solution that allows you to track URL changes.

  1. For Android applications:
    1. Create an object of the AndroidSDKSocialAuthHelper class.
    2. Call the PerformSocialAuth method and pass the following parameters to the method:
      • SocialProvider — the name of the social network
      • onSuccess — successful user authentication callback
      • onCancelled — user cancels authentication callback
      • onError — error callback
    3. Get the token that the onSuccess callback returns in the token parameter and use it in requests to the Xsolla servers.
Note
An example of the implementation of this logic is available in the Assets/Xsolla.Demo/Login/Scripts/Login/Auth/AndroidSocialAuth.cs script of the demo project.
  1. For iOS applications:
    1. Create an object of the IosSDKSocialAuthHelper class.
    2. Call the PerformSocialAuth method and pass the following parameters to the method:
      • SocialProvider — the name of the social network
      • onSuccess — successful user authentication callback
      • onCancelled — user cancels authentication callback
      • onError — error callback
    3. Get the token that the onSuccess callback returns in the access_token field of the LoginOAuthJsonResponse object and use it in requests to the Xsolla servers.
Note
An example of the implementation of this logic is available in the Assets/Xsolla.Demo/Login/Scripts/Login/Auth/IosSocialAuth.cs script of the demo project.
Cet article vous a été utile ?
Merci !
Que pouvons-nous améliorer ? Message
Nous sommes désolés de l'apprendre
Dites-nous pourquoi vous n'avez pas trouvé cet article utile. Message
Merci pour votre commentaire !
Nous examinerons votre message et l'utiliserons pour améliorer votre expérience.
Masquer

Comment configurer l'authentification native via les réseaux sociaux

Native authentication lets users log in to your application via a social network account configured on a mobile device.

The first time a user logs in, the social networking application is launched and asks for permission to authenticate the user. After that, authentication is performed automatically without requiring the user to do anything.

Currently, SDK has implemented native authentication via the following social networks:

  • Google
  • Facebook
  • WeChat
  • QQ

To configure native authentication:

  1. In the application interface, add buttons for authentication via social networks.
  2. Create your Unity project build for Android.
  3. Configure the application in the developer account for the social network:
    1. For authentication via Facebook:
      1. Register and create a new application.
      2. Set up the application page in your Facebook developer account.
    2. For authentication via Google, set up the project in Google API Console.
    3. For authentication via WeChat:
      1. Register and create a new application.
      2. Submit the application for review.
    4. For authentication via QQ:
      1. Register and create a new application.
      2. Submit the application for review.

  1. Set up authentication via social networks on the Xsolla side:
    1. For Facebook and Google, set up social connections in Publisher Account.
    2. For WeChat and QQ, contact your Account Manager.
  2. Set up the asset for your Unity project.
  3. Implement authentication logic on the application side.

Créer un build de projet Unity pour Android

  1. Go to your Unity project.
  2. Click File > Build settings in the main menu.
  3. Click Android in the Platform panel.
  4. Click Build.

For further native authentication configuration you will need:

  • Package name found in the Package Name field in the Inspector panel after selecting the Android platform in File > Build settings.
  • Android class name — the class name of the main activity, including the namespace of the application (e.g., com.domain.appname.activity). The class name can be found in AndroidManifest.xml. The main activity’s tag should contain an intent-filter tag with the android.intent.action.MAIN action and the android.intent.category.LAUNCHER category.
  • Android hash key. You can get it with OpenSSL.

Configurer une page d'application dans le compte de développeur Facebook

  1. Go to project settings in the Facebook developer account.
  2. Go to Settings > Basic.
  3. Click Add Platform and select Android.
  4. Specify package name from your Unity project in the Google Play Package Name field.
  5. Specify Android class name from your Unity project in the Class Name field.
  6. Specify Android hash key from your Unity project in the Key Hashes filed.
  7. Click Save Changes.

For further native authentication configuration, you will need App ID and App Secret found in project settings in Settings > Basic section.

Configurer un projet dans Google API Console

  1. Go to Google API Console.
  2. Click New Project.
  3. Specify Project name and Location and click Save.
  4. Go to the created project and click OAuth consent screen in the side menu.
  5. Select External option and click Create.
  6. Specify the necessary parameters and click Save.
  7. Click Credentials in the side menu.
  8. Create an OAuth 2.0 client for your Unity application:
    1. Click Create credentials and select OAuth client ID.
    2. Specify Android in the Application type field.
    3. Specify Name.
    4. Specify package name from your Unity project in the Package name field.
    5. Specify Android hash key from your Unity project in the SHA-1 certificate fingerprint field.
    6. Click Create.
    7. Click OK.
  1. Create an OAuth 2.0 client for the web application:
    1. Click Create credentials and select OAuth client ID.
    2. Specify Web application in the Application type field.
    3. Specify Name.
    4. Click Add URI in the Authorized redirect URIs section and specify https://login.xsolla.com/api/social/oauth2/callback URI.
    5. Click Create.
    6. Click OK.

For further native authentication configuration, you will need Client ID and Client Secret found in settings of the Client ID for the web application.

Configurer les réseaux sociaux pour le projet de connexion dans le Compte éditeur Xsolla

Avis
In Publisher Account, ensure the Classic login and Social login option are selected for the Login project that you use in your application. You can change the login method later by clicking the Change Login method link. Previously saved settings will not be lost.
  1. Open your project in Publisher Account.
  2. In the side menu, сlick Login.
  3. Click Configure in the pane of a Login project.
  4. On the navigation page, go to the Authentication block and select Social login section.
  1. To set up a social network, go to the social network card, click the ⚙ icon to the right of the title, and select Connect.
Note
To use social network authorization, in the social network card settings, specify the Application ID and secret of the application in your project. The Application ID and secret are available from the developer account of the social provider. Detailed instructions for locating the Application ID and secret are available in the social network card settings in Publisher Account.

Configurer un asset pour le projet Unity

  1. Go to your Unity project.
  2. Click Window > Xsolla > Edit Settings in the main menu.
  3. Specify the application ID:
    1. Specify App ID from the Facebook developer account in the Facebook App ID field.
    2. Specify Client ID for a web application from the Google API Console in the Google server ID field.
    3. Specify AppID from the WeChat application settings in the WeChat App ID field.
    4. Specify AppID from the QQ application settings in the QQ App ID field.

Intégration côté application

Implement the following logic when clicking the social login button:

  • For Android applications, create an instance of AndroidSDKSocialAuthHelper and call the PerformSocialAuth method. An implementation example is provided in the Assets/Xsolla.Demo/Login/Scripts/Login/Auth/AndroidSocialAuth.cs script in the demo project.
  • For iOS applications, create an instance of IosSDKSocialAuthHelper and call the PerformSocialAuth method. An implementation example is provided in the Assets/Xsolla.Demo/Login/Scripts/Login/Auth/IosSocialAuth.cs script in the demo project.
Cet article vous a été utile ?
Merci !
Que pouvons-nous améliorer ? Message
Nous sommes désolés de l'apprendre
Dites-nous pourquoi vous n'avez pas trouvé cet article utile. Message
Merci pour votre commentaire !
Nous examinerons votre message et l'utiliserons pour améliorer votre expérience.
Masquer

Liens utiles

Dernière mise à jour: 10 Octobre 2023

Faute de frappe ou autre erreur dans le texte ? Sélectionnez le texte concerné et appuyez sur Ctrl+Entée.

Signaler un problème
Nous améliorons continuellement notre contenu grâce à vos commentaires.
Indiquez votre adresse e-mail pour un suivi
Merci pour votre commentaire !