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

# Configurer la connexion avec Battle.net pour PlayFab

> Configurez l'authentification PlayFab avec Battle.net à l'aide de HTML5 et JavaScript, y compris la configuration de l'application Blizzard, le flux OAuth et l'intégration de la connexion des joueurs.

# Configurer l'authentification PlayFab avec Battle.net

Ce tutoriel vous guide tout au long du processus de configuration de l'authentification PlayFab à l'aide de Battle.net et de HTML5/JavaScript.

## Exigences

Vous avez besoin de :

* Un [compte Battle.net](https://developer.battle.net) à des fins de test.
* Un titre [PlayFab](https://developer.playfab.com/) enregistré.
* Une bonne connaissance des [notions de base et pratiques exemplaires de connexion](/fr-CA/services/playfab/identity/player-identity/login/login-basics-best-practices).
* Un serveur doté d'un nom de domaine valide pour servir un fichier HTML statique. Consultez le tutoriel [Exécution d'un serveur HTTP à des fins de test](/fr-CA/services/playfab/identity/player-identity/platform-specific-authentication/running-an-http-server-for-testing) pour savoir comment en configurer un.

## Serveur et domaine

Pour suivre ce guide, vous avez besoin d'un serveur doté d'un domaine valide. Si vous n'avez pas encore de domaine enregistré ni de serveur Web distant, suivez notre tutoriel [Exécution d'un serveur HTTP à des fins de test](/fr-CA/services/playfab/identity/player-identity/platform-specific-authentication/running-an-http-server-for-testing) pour savoir comment exécuter un serveur Web local doté d'un nom de domaine valide.

Tout au long de ce guide, nous supposons que votre domaine est [http://playfab.example](http://playfab.example).

## Récupérer l'ID client du titre Battle.net

Commencez par accéder à [Battle.net](https://developer.battle.net) et créez un compte de développeur Battle.net. Une fois votre compte créé, vous devez créer un titre et vous faire attribuer des ID clients.

## Installer le module complémentaire Battle.net

Accédez à la page **Game Manager** de PlayFab pour votre titre.

1. Accédez à **Add-ons** dans le menu.
2. Repérez et ouvrez l'icône ou le lien **Battle.net Add-on**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-partner-add-on-page.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=de4613079755faeb998407ac4158da89" alt="Module complémentaire de PlayFab Game Manager" width="1248" height="555" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-partner-add-on-page.png" />

3. Sélectionnez **Install Battle.net**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-add-on.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=f9828e789c2285bbde0d456d7f307102" alt="Module complémentaire Battle.net de PlayFab Game Manager" width="1248" height="545" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-add-on.png" />

4. Remplissez le champ **Client ID for Game Client**.
5. Vous pouvez également remplir le champ **Client ID for Game Server**.
6. Sélectionnez ensuite le bouton **Save settings**.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-validated.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=1fe7a49156f04e31ae204c6f7ce6a9ef" alt="ID clients du module complémentaire Battle.net de PlayFab Game Manager" width="1248" height="650" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-validated.png" />

Battle.net apparaît comme actif dans la page Add-on.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-partner-add-on-page-active.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=42e07d365b7f93b5e3014039e91ac91b" alt="Module complémentaire Battle.net de PlayFab Game Manager actif" width="1248" height="561" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-partner-add-on-page-active.png" />

## Tests à l'aide d'un jeton d'accès

Dans cet exemple, nous montrons comment tester l'API LoginWithBattleNet à l'aide de l'approche classique par jeton d'accès. Utilisez le code HTML fourni pour vos tests.

<Note>
  *Assurez-vous* de remplacer `YOUR_CLIENT_ID`, `YOUR_PLAYFAB_TITLE_ID`, `YOUR_BNET_TITLE_NAME` et `YOUR_CLIENT_SECRET` par vos propres valeurs.
</Note>

```html theme={null}
<!DOCTYPE html>
<html>
<head>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
    <h2>Battle.net SSO Token Demo (Manual Flow)</h2>
    <ol>
        <li>
            <button onclick="openBattleNetLogin()">Log in to Battle.net</button>
        </li>
        <li>
            After login, copy the <b>ST</b> value from the URL (e.g. <code>ST=US-xxxx-xxxx) and paste it here:
            

            <input type="text" id="ssoToken" size="80" placeholder="Paste SSO token (ST=...)" />
        </li>
        <li>
            Click "Exchange SSO Token for id_token"

            <button onclick="exchangeSSOToken()">Exchange SSO Token for id_token</button>
            

            <label>id_token:</label>

            <input type="text" id="idToken" size="80" placeholder="id_token will appear here" />
        </li>
        <li>
            Click "Login to PlayFab" to complete the flow

            <button onclick="loginWithPlayFab()">Login to PlayFab</button>
        </li>
    </ol>
    

    <div id="log"></div>
    <script>
        // Demo configuration variables
        const BNET_TITLE_NAME = 'YOUR_BNET_TITLE_NAME';
        const PLAYFAB_TITLE_ID = 'YOUR_PLAYFAB_TITLE_ID';
        const CLIENT_ID = 'YOUR_CLIENT_ID';
        const CLIENT_SECRET = 'YOUR_CLIENT_SECRET';

        function openBattleNetLogin() {
            const url = `http://account.battle.net/login/en/?app=${encodeURIComponent(BNET_TITLE_NAME)}`;
            window.open(url, '_blank');
        }

        function exchangeSSOToken() {
            const ssoToken = document.getElementById('ssoToken').value.trim();
            if (!ssoToken) {
                logLine("Please enter the SSO token.");
                return;
            }
            logLine("Exchanging SSO token for id_token...");
            // Prepare the request for the token exchange
            const params = new URLSearchParams();
            params.append('scope', 'account.basic openid');
            params.append('grant_type', 'urn:ietf:params:oauth:grant-type:token-exchange');
            params.append('subject_token', ssoToken);
            params.append('subject_token_type', 'urn:blizzard:params:oauth:token-type:sso');
            params.append('requested_token_type', 'urn:ietf:params:oauth:token-type:jwt');

            // Basic Auth header
            const authHeader = 'Basic ' + btoa(CLIENT_ID + ':' + CLIENT_SECRET);

            fetch('https://oauth.battle.net/token', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Authorization': authHeader
                },
                body: params
            })
            .then(res => res.json())
            .then(data => {
                if (data.id_token) {
                    document.getElementById('idToken').value = data.id_token;
                    logLine("id_token received.");
                } else {
                    logLine("Error: " + JSON.stringify(data));
                }
            })
            .catch(err => logLine("Error: " + err));
        }

        function loginWithPlayFab() {
            const idToken = document.getElementById('idToken').value.trim();
            if (!idToken) {
                logLine("Please exchange for an id_token first.");
                return;
            }
            logLine("Logging in to PlayFab...");
            axios.post(
                `https://${PLAYFAB_TITLE_ID}.playfabapi.com/Client/LoginWithBattleNet`,
                {
                    TitleId: PLAYFAB_TITLE_ID,
                    IdentityToken: idToken,
                    CreateAccount: true
                },
                {
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }
            )
            .then(response => logLine("Response: " + JSON.stringify(response.data)))
            .catch(error => logLine("Error: " + JSON.stringify(error.response ? error.response.data : error)));
        }

        function logLine(message) {
            const logDiv = document.getElementById('log');
            logDiv.innerHTML += message + "
";
        }
    </script>
</body>
</html></code>
```

N'oubliez pas d'ouvrir la page HTML à l'aide de votre serveur Web, et assurez-vous d'accéder à cette page au moyen de l'URL que vous avez spécifiée.

1. Une fois la page ouverte, sélectionnez **Log in to Battle.net**.
2. Après la connexion, copiez la valeur **ST** de l'URL (par exemple : ST=US-xxxx-xxxx) et entrez-la dans la boîte de dialogue.
3. Sélectionnez **Exchange SSO Token for id\_token** et copiez la valeur dans la boîte de dialogue.
4. Sélectionnez **Login to PlayFab** pour terminer le flux de connexion.
5. Une fois terminé, le script tente de s'authentifier du côté de PlayFab et affiche le résultat.

<img src="https://mintcdn.com/microsoft-4404708b/mLCHf0iQv3VidfBe/images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-token-demo.png?fit=max&auto=format&n=mLCHf0iQv3VidfBe&q=85&s=6436d543b2543a12c1842bb36ad4021d" alt="Exemple d'authentification Battle.net" width="2027" height="961" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-token-demo.png" />


## Related topics

- [Connexion avec Battle.net](/fr-CA/services/playfab/api-references/rest/client/authentication/login-with-battle-net.md)
- [Version 0.2.0 de l'exemple XBOX Godot](/fr-CA/build/gdk-and-engines/godot-release-notes/godot-release-notes-0-2-0.md)
- [Notes de version du SDK PlayFab Services 2025](/fr-CA/services/playfab/release-notes/2025.md)
- [PFAuthenticationLoginWithBattleNetRequest](/fr-CA/services/playfab/api-references/c/pfauthenticationtypes/structs/pfauthenticationloginwithbattlenetrequest.md)
- [PFAuthenticationServerLoginWithBattleNetRequest](/fr-CA/services/playfab/api-references/c/pfauthenticationtypes/structs/pfauthenticationserverloginwithbattlenetrequest.md)
