> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration de l'authentification PlayFab avec Kongregate et Unity

> Tutoriel pas à pas pour ajouter l'authentification Kongregate à un titre PlayFab dans Unity avec WebGL, couvrant le téléversement de l'application Kongregate et le code de connexion des joueurs.

Ce tutoriel présente la configuration minimale requise pour authentifier vos joueurs dans PlayFab avec Kongregate et Unity.

## Configuration requise

* Un compte [Kongregate](https://www.kongregate.com/) enregistré.
* Une bonne connaissance du [guide des développeurs Kongregate](https://www.kongregate.com/developer_center/docs/en/kongregate-api).
* Un titre PlayFab enregistré.
* Un projet Unity avec PlayFab configuré pour votre titre.
* La prise en charge de Unity WebGL installée.
* Une bonne connaissance des [principes de base et meilleures pratiques de connexion](/fr/services/playfab/identity/player-identity/login/login-basics-best-practices).

## Configuration d'une application Kongregate

Kongregate exige que vous téléversiez une version préliminaire de l'application avant de pouvoir accéder aux informations d'application nécessaires. Notre première étape consiste à préparer un fichier **index.html** avec le contenu ci-dessous.

```html theme={null}
<!doctype html>
<html lang="en-us">
<head></head>
<body>
 <h1>Placeholder</h1>
</body>
</html>
```

Accédez au [site web de Kongregate](https://www.kongregate.com/).

1. Sélectionnez l'onglet **Games**.
2. Sélectionnez ensuite le bouton **Upload your game**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-games-tab.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=3af3bc93c645a3f8948701caf1f08d03" alt="Onglet Games de Kongregate" width="965" height="471" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-games-tab.png" />

Une page de configuration d'une nouvelle application s'ouvre.

1. Veillez à saisir le **nom de l'application**.
2. Saisissez une **description du jeu**.
3. Sélectionnez ensuite une **catégorie**.
4. Soumettez la nouvelle application en sélectionnant le bouton **Continue**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-upload-your-game.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=0e66a21c81da6861bd59d2dddb82c22f" alt="Téléversement de votre jeu sur Kongregate" width="636" height="603" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-upload-your-game.png" />

Vous êtes redirigé vers la page **Application Upload**.

Avant tout, *et c'est le plus important*, veillez à enregistrer l'URL figurant dans la **barre d'adresse** de votre navigateur dans un endroit sûr et facilement accessible. *Cela vous fera gagner beaucoup de temps pour retrouver l'accès à l'application une fois la page fermée*.

1. Une fois cela fait, sélectionnez le fichier **index.html** préparé comme **Game File**.
2. Configurez ensuite la taille de l'écran.
3. Veillez à accepter toutes les licences requises.
4. Enfin, téléversez votre application en sélectionnant le bouton **Upload**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-app-upload-page.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=893af9198a1deef8b7cdb6bcd4534cc9" alt="Page de téléversement d'application Kongregate" width="792" height="1120" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-app-upload-page.png" />

Une fois l'aperçu ouvert, ignorez le contenu et ouvrez le lien **api information**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-preview-api-info.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=b136fa2e3dd827e4b6344921b500a8be" alt="Informations d'API de l'aperçu Kongregate" width="786" height="432" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-preview-api-info.png" />

Lorsque la page **API Information** s'ouvre, repérez l'**API Key** et conservez-la dans un endroit sûr et facilement accessible pour une utilisation ultérieure.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-api-key.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=a99770329d85ce86613cd0a32cdf28a4" alt="Clé API Kongregate" width="900" height="344" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-api-key.png" />

## Configuration du titre PlayFab

Dans le Game Manager de votre titre PlayFab :

1. Sélectionnez **Add-ons** dans le menu de gauche.
2. Repérez et sélectionnez l'icône **Kongregate**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-select-kongregate-add-on.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=e25c251fc51474717d5b5a693ad1bf0c" alt="Sélection du module complémentaire Kongregate dans PlayFab" width="1100" height="685" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-select-kongregate-add-on.png" />

Une nouvelle page s'ouvre, vous permettant de configurer l'intégration **Kongregate** :

1. Saisissez l'**API Key** obtenue dans la section précédente.
2. Sélectionnez le bouton **Install Kongregate**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-set-up-kongregate-integration.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=fa6dd5111bfe1bb60c6cf118622272c1" alt="Configuration de l'intégration Kongregate dans PlayFab" width="1000" height="693" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-set-up-kongregate-integration.png" />

À ce stade, si vous ne recevez aucun message d'erreur, l'intégration de votre titre PlayFab avec votre application Kongregate est correctement configurée.

## Configuration d'un projet Unity

Utilisez cette liste de contrôle pour configurer Unity :

* \[FACULTATIF] Installez les [PlayFab Editor Extensions](https://aka.ms/playfabunityextension).
  * Définissez votre `TitleId` dans le Scriptable Object `PlayFabSharedSettings`.
* Pour Unity 5.6+, téléchargez le [modèle WebGL Kongregate Preloader](https://github.com/kongregate/webgl-preloader) et placez-le dans le dossier `Assets/WebGLTemplates` **(2)**.
* Pour Unity \< 5.6, téléchargez le [modèle WebGL Kongregate Preloader pour 5.5 et versions antérieures](https://github.com/kongregate/webgl-preloader/tree/unity-5.5-and-below) et placez-le dans le dossier `Assets/WebGLTemplates` **(2)**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-assets-webgltemplates-folder.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=39cc86d08fbb657aeda84d76445ebfdc" alt="Dossier Assets/WebGL Templates de Unity" width="319" height="307" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-assets-webgltemplates-folder.png" />

Créons maintenant votre scène de travail.

1. À des fins de test, utilisez un canevas à mise à l'échelle d'écran avec quelques étiquettes de texte.

<Note>
  Nous n'aurons besoin que d'*une seule* étiquette de texte pour afficher les messages de débogage.
</Note>

2. Créez un **GameObject** vide et renommez-le **Kongregate**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-boot-scene.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=e347519d8ee348c2ab91d4d8de0df7df" alt="BootScene Unity" width="337" height="300" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-boot-scene.png" />

Ce `GameObject` contiendra un composant `KongregateHandler` relié à une étiquette de texte pour les messages de débogage.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-kongregate-handler.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=a9ff459d8fc93be7aa71875a18ef1497" alt="GameObject Unity avec Kongregate Handler" width="433" height="310" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-kongregate-handler.png" />

Le code du composant `KongregateHandler` est fourni ci-dessous.

```csharp theme={null}
// We are specifically interested in importing PlayFab related namespaces
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
using UnityEngine.UI;

public class KongregateHandler : MonoBehaviour
{
  
    // Standard unity callback, executed once for the script to start
    public void Start()
    {
        // Utility: show feedback
        SetMessage("Loading kongregate api...");

        /*
         * Important: execute Javascript in the external context to initialize
         * Kongregate API, Unity Support and set up callback GameObject and Method.
         * In this case, callback is set to a GameObject called Kongregate and a
         * method called OnKongregateAPILoaded, which we define later in this class.
         * Once Kongregate API is initialized, Unity will locate this object by name
         * ("Kongregate") and execute a method "OnKongregateAPILoaded" passing in user
         * info string as an argument.
         */
        Application.ExternalEval(
          "if(typeof(kongregateUnitySupport) != 'undefined'){" +
          " kongregateUnitySupport.initAPI('Kongregate', 'OnKongregateAPILoaded');" +
          "} else {" +
          " console.error('No unity support!');" +
          "};"
        );
    }

    /*
     * Executed once Kongregate API is ready. This method is invoked by KongregateAPI
     * and receives a structured text with multiple pieces of data you must parse manually.
     * The userInfo string parameter has the following structure: 'user_identifier|user_name|auth_token'
     */
    public void OnKongregateAPILoaded(string userInfo)
    {
        SetMessage("Received user info! Logging though playfab...");

        // We split userInfo string using '|' character to acquire auth token and Kongregate ID.
        var userInfoArray = userInfo.Split('|');
        var authTicket = userInfoArray[2];
        var kongregateId = userInfoArray[0];

        LogToBrowser("Auth Token: " + authTicket);
        LogToBrowser("Kongregate Id: " + kongregateId);

        /*
         * We then execute PlayFab API call called LoginWithKongregate.
         * LoginWithKongregate requires KongregateID and AuthTicket.
         * We also pass CreateAccount flag, to automatically create player account.
         */
        PlayFabClientAPI.LoginWithKongregate(new LoginWithKongregateRequest
        {
            KongregateId = kongregateId,
            AuthTicket = authTicket,
            CreateAccount = true
        }, OnLoggedIn, OnFailed);
    }

    /*
     * The rest of the code serves as a utility to process results, log debug statements
     * and display them using Text message label.
     */

    private void OnLoggedIn(LoginResult obj)
    {
        SetMessage("Logged in through PlayFab!");
    }
    private void OnFailed(PlayFabError error)
    {
        SetMessage("Failed to login in with PlayFab: " + error.GenerateErrorReport());
    }

    private void SetMessage(string message)
    {
        InfoLabel.text = message;
    }

    private void LogToBrowser(string message)
    {
        Application.ExternalEval(string.Format("console.log('{0}')", message));
    }

    public Text InfoLabel;
}
```

## Test

La seule façon de vraiment tester l'intégration est de téléverser votre prototype sur Kongregate.

1. Ouvrez la fenêtre **Build** et vérifiez que **WebGL** est sélectionné dans votre menu.
2. Ouvrez ensuite les **Player Settings** en sélectionnant le bouton.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-build-settings.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=b7c6c11c30498759dcbb81505e6de17e" alt="Paramètres de build Kongregate" width="628" height="605" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-build-settings.png" />

Dans l'écran **Player Settings**, repérez la section **Settings for WebGL** :

1. Vérifiez que la taille est correctement configurée.
2. Sélectionnez ensuite le **Kongregate Preloader Template**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-webgl-settings.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=d317f83e3db4d3b5c5d6921721e56e08" alt="Paramètres WebGL Kongregate" width="424" height="421" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-webgl-settings.png" />

Générez l'application et ouvrez le dossier **Build**.

* Vous obtiendrez un fichier **index.html** et plusieurs autres fichiers (selon la version de Unity).
* Prenez tous les fichiers à l'exception de **index.html** et placez-les dans une archive zip, comme indiqué dans l'exemple ci-dessous.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-build-folder.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=d632515d669b433a5afbcc1f19db6ddd" alt="Dossier de build Unity" width="795" height="155" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-build-folder.png" />

Utilisez l'URL enregistrée précédemment pour accéder à votre page **Application Upload**.

1. Sélectionnez **index.html** comme **Game File**.
2. Sélectionnez ensuite l'archive zip comme **Additional files**.
   * Acceptez les licences et téléversez.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-app-upload-page-add-files.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=a48c5ef005ca1aa2f674842d7cdb9fa5" alt="Page de téléversement d'application Kongregate - Ajout de fichiers" width="679" height="345" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-app-upload-page-add-files.png" />

Une fois l'aperçu ouvert, vous devriez voir votre jeu en direct à mesure que le message change.

À la fin, le message doit indiquer une connexion réussie via PlayFab.

À ce stade, vous avez intégré avec succès PlayFab et Kongregate.


## Related topics

- [Authentification spécifique à la plateforme](/fr/services/playfab/identity/player-identity/platform-specific-authentication/index.md)
- [Configuration de l'authentification PlayFab avec Kongregate et HTML5](/fr/services/playfab/identity/player-identity/platform-specific-authentication/kongregate-html5.md)
- [Configuration de l'authentification PlayFab avec Steam et Unity](/fr/services/playfab/identity/player-identity/platform-specific-authentication/steam-unity.md)
- [Configuration de l'authentification PlayFab avec Facebook et Unity](/fr/services/playfab/identity/player-identity/platform-specific-authentication/facebook-unity.md)
- [Configuration de l'authentification PlayFab avec Google et HTML5](/fr/services/playfab/identity/player-identity/platform-specific-authentication/google-html5.md)
