> ## 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.

# Configuración de la autenticación de PlayFab con Kongregate y Unity

> Tutorial paso a paso para agregar la autenticación de Kongregate a un título de PlayFab en Unity con WebGL, que abarca la carga de la aplicación de Kongregate y el código de inicio de sesión del jugador.

Este tutorial muestra la configuración mínima necesaria para autenticar a los jugadores en PlayFab mediante Kongregate y Unity.

## Requisitos

* Una cuenta registrada de [Kongregate](https://www.kongregate.com/).
* Familiaridad con la [Guía para desarrolladores de Kongregate](https://www.kongregate.com/developer_center/docs/en/kongregate-api).
* Un título de PlayFab registrado.
* Un proyecto de Unity con PlayFab configurado para el título.
* Compatibilidad con Unity WebGL instalada.
* Familiaridad con [Conceptos básicos de inicio de sesión y procedimientos recomendados](/services/playfab/identity/player-identity/login/login-basics-best-practices).

## Configuración de una aplicación de Kongregate

Kongregate requiere que cargue una versión preliminar de la aplicación antes de obtener acceso a la información necesaria de la aplicación. Nuestro primer paso es preparar un archivo **index.html** con el contenido que se muestra a continuación.

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

Vaya al [sitio web de Kongregate](https://www.kongregate.com/).

1. Seleccione la pestaña **Games**.
2. Después, seleccione el botón **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="Pestaña Games de Kongregate" width="965" height="471" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-games-tab.png" />

Se abrirá una página para configurar una nueva aplicación.

1. Asegúrese de escribir el **Application Name**.
2. Escriba una **Game Description**.
3. Después, seleccione una **Category**.
4. Envíe la nueva aplicación seleccionando el botón **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="Kongregate: cargar el juego" width="636" height="603" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-upload-your-game.png" />

Se le transferirá a la página **Application Upload**.

En primer lugar (*y esto es lo más importante*), asegúrese de guardar la dirección URL de la **barra de direcciones web** en un lugar seguro y de fácil acceso. *Esto le ahorrará mucho tiempo al restaurar el acceso a la aplicación una vez que cierre la página*.

1. Una vez hecho esto, seleccione el archivo **index.html** preparado como **Game File**.
2. Después, configure el tamaño de la pantalla.
3. Asegúrese de aceptar todas las licencias necesarias.
4. Por último, cargue la aplicación seleccionando el botón **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="Página de carga de aplicaciones de Kongregate" width="792" height="1120" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-app-upload-page.png" />

Cuando se abra la vista previa, ignore el contenido y abra el vínculo **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="Información de la API en la vista previa de Kongregate" width="786" height="432" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-preview-api-info.png" />

Cuando se abra la página **API Information**, busque la **API Key** y guárdela en un lugar seguro y de fácil acceso para su uso posterior.

<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="Clave de API de Kongregate" width="900" height="344" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-api-key.png" />

## Configuración del título de PlayFab

En Game Manager del título de PlayFab:

1. Seleccione **Add-ons** en el menú de la izquierda.
2. Busque y seleccione el icono de **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="PlayFab: seleccionar el complemento de Kongregate" width="1100" height="685" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-select-kongregate-add-on.png" />

Se abrirá una nueva página que le permitirá configurar la integración con **Kongregate**:

1. Escriba la **API Key** que adquirió en la sección anterior.
2. Seleccione el botón **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="PlayFab: configurar la integración con Kongregate" width="1000" height="693" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/playfab-set-up-kongregate-integration.png" />

En este momento, si no recibe ningún mensaje de error, habrá configurado correctamente la integración del título de PlayFab con la aplicación de Kongregate.

## Configuración de un proyecto de Unity

Use esta lista de comprobación de configuración de Unity:

* \[OPCIONAL] Instale las [extensiones del editor de PlayFab](https://aka.ms/playfabunityextension).
  * Configure `TitleId` en el objeto Scriptable Object `PlayFabSharedSettings`.
* Para Unity 5.6+, descargue la [plantilla WebGL de Kongregate Preloader](https://github.com/kongregate/webgl-preloader) y colóquela dentro de la carpeta `Assets/WebGLTemplates` **(2)**.
* Para Unity \< 5.6, descargue la [plantilla WebGL de Kongregate Preloader para 5.5 e inferiores](https://github.com/kongregate/webgl-preloader/tree/unity-5.5-and-below) y colóquela dentro de la carpeta `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="Carpeta 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" />

Ahora vamos a crear la escena de trabajo.

1. Con fines de prueba, use un lienzo con escalado de pantalla con un par de etiquetas de texto.

<Note>
  Solo necesitaremos *una* etiqueta de texto para mostrar mensajes de depuración.
</Note>

2. Cree un **GameObject** vacío y cámbiele el nombre a **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 de Unity" width="337" height="300" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-boot-scene.png" />

Este `GameObject` contendrá un componente `KongregateHandler` con una etiqueta de texto conectada para los mensajes de depuración.

<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 Kongregate Handler de Unity" width="433" height="310" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-kongregate-handler.png" />

El código del componente `KongregateHandler` se proporciona a continuación.

```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;
}
```

## Pruebas

La única manera de probar realmente la integración es cargar el prototipo en Kongregate.

1. Abra la ventana **Build** y asegúrese de que **WebGL** esté seleccionado en el menú.
2. Después, abra **Player Settings** seleccionando el botón.

<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="Configuración de compilación de Kongregate" width="628" height="605" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-build-settings.png" />

Dentro de la pantalla **Player Settings**, busque la compilación **Settings for WebGL**:

1. Compruebe que el tamaño esté configurado correctamente.
2. Después, seleccione **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="Configuración de WebGL de Kongregate" width="424" height="421" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-webgl-settings.png" />

Compile la aplicación y abra la carpeta **Build**.

* Obtendrá un archivo **index.html** y un conjunto de otros archivos (según la versión de Unity).
* Tome todos los archivos excepto **index.html** y colóquelos dentro de un archivo zip, como se muestra en el ejemplo que se proporciona a continuación.

<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="Carpeta de compilación de Unity" width="795" height="155" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/unity-build-folder.png" />

Use la dirección URL que guardó anteriormente para acceder a la página **Application Upload**.

1. Seleccione **index.html** como **Game File**.
2. Después, seleccione el archivo zip como **Additional files**.
   * Acepte las licencias y cargue.

<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="Página de carga de aplicaciones de Kongregate: agregar archivos" width="679" height="345" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/kongregate-unity/kongregate-app-upload-page-add-files.png" />

Cuando se abra la vista previa, debería poder ver el juego en directo a medida que cambia el mensaje.

Al finalizar, el mensaje debería indicar que el inicio de sesión a través de PlayFab se realizó correctamente.

En este momento, habrá integrado correctamente PlayFab y Kongregate.


## Related topics

- [Autenticación específica de la plataforma](/es/services/playfab/identity/player-identity/platform-specific-authentication/index.md)
- [Configuración de la autenticación de PlayFab con Kongregate y HTML5](/es/services/playfab/identity/player-identity/platform-specific-authentication/kongregate-html5.md)
- [Configuración de la autenticación de PlayFab con Facebook y Unity](/es/services/playfab/identity/player-identity/platform-specific-authentication/facebook-unity.md)
- [Configuración de la autenticación de PlayFab con Steam y Unity](/es/services/playfab/identity/player-identity/platform-specific-authentication/steam-unity.md)
- [Autenticación de PlayFab con el inicio de sesión de Google Play Games en Unity](/es/services/playfab/identity/player-identity/platform-specific-authentication/google-sign-in-unity.md)
