> ## 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, notamment 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 HTML5/JavaScript.

## Configuration requise

Vous avez besoin des éléments suivants :

* Un [compte Battle.net](https://developer.battle.net) pour les tests.
* Un titre [PlayFab](https://developer.playfab.com/) inscrit.
* Une connaissance des [notions de base et bonnes pratiques de connexion](/fr/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 pour les tests](/fr/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 ne disposez pas encore d'un domaine inscrit et d'un serveur web distant, suivez notre tutoriel [Exécution d'un serveur HTTP pour les tests](/fr/services/playfab/identity/player-identity/platform-specific-authentication/running-an-http-server-for-testing) pour savoir comment configurer un serveur web local avec 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 le Client ID 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 voir attribuer des Client IDs.

## 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. Recherchez et ouvrez l'icône/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 dans 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 dans PlayFab Game Manager" width="1248" height="545" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-add-on.png" />

4. Renseignez le champ **Client ID for Game Client**.
5. Si vous le souhaitez, renseignez 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="Client IDs du module complémentaire Battle.net dans 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 des modules complémentaires.

<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 actif dans PlayFab Game Manager" width="1248" height="561" data-path="images/playfab/identity/player-identity/platform-specific-authentication/tutorials/battlenet/battlenet-partner-add-on-page-active.png" />

## Test à 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>
  *Veillez* à 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 veillez à accéder à cette page à l'aide 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 vous être connecté, copiez la valeur **ST** à partir de l'URL (par exemple : ST=US-xxxx-xxxx) et saisissez-la dans la zone de dialogue.
3. Sélectionnez **Exchange SSO Token for id\_token** et copiez la valeur dans la zone de dialogue.
4. Sélectionnez **Login to PlayFab** pour terminer le flux de connexion.
5. Une fois terminé, le script tente de s'authentifier côté 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

- [Configurer Se connecter avec Apple pour PlayFab](/fr/services/playfab/identity/player-identity/platform-specific-authentication/apple-open-id/overview.md)
- [Authentification PlayFab avec la connexion Google Play Games dans Unity](/fr/services/playfab/identity/player-identity/platform-specific-authentication/google-sign-in-unity.md)
- [Se connecter avec Battle Net](/fr/services/playfab/api-references/rest/client/authentication/login-with-battle-net.md)
- [Notes de version du SDK PlayFab Services 2025](/fr/services/playfab/release-notes/2025.md)
- [Version v0.2.0 de l'exemple XBOX Godot](/fr/build/gdk-and-engines/godot-release-notes/godot-release-notes-0-2-0.md)
