{"meta":{"title":"Authentification","intro":"Le sdk GitHub Copilot prend en charge plusieurs méthodes d’authentification pour répondre à différents cas d’usage. Choisissez la méthode qui correspond le mieux à votre scénario de déploiement.","product":"GitHub Copilot","breadcrumbs":[{"href":"/fr/copilot","title":"GitHub Copilot"},{"href":"/fr/copilot/how-tos","title":"Procédures"},{"href":"/fr/copilot/how-tos/copilot-sdk","title":"Kit de développement logiciel (SDK) Copilot"},{"href":"/fr/copilot/how-tos/copilot-sdk/auth","title":"Authentification"},{"href":"/fr/copilot/how-tos/copilot-sdk/auth/authenticate","title":"Authenticate"}],"documentType":"article"},"body":"# Authentification\n\nLe sdk GitHub Copilot prend en charge plusieurs méthodes d’authentification pour répondre à différents cas d’usage. Choisissez la méthode qui correspond le mieux à votre scénario de déploiement.\n\n<!-- markdownlint-disable GHD046 GHD005 -->\n\n<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->\n\n## Méthodes d’authentification\n\n| Méthode                                                                                            | Cas d’usage                                                                          | abonnement Copilot requis                                       |\n| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------------- |\n| [GitHub Utilisateur connecté](#github-signed-in-user)                                              | Applications interactives où les utilisateurs se connectent avec GitHub              | Oui                                                             |\n| [application GitHub OAuth](#github-oauth-app)                                                      | Applications agissant pour le compte des utilisateurs via OAuth                      | Oui                                                             |\n| [Variables d’environnement](#environment-variables)                                                | CI/CD, automatisation, serveur à serveur                                             | Oui                                                             |\n| [Authentification serveur à serveur](/fr/copilot/how-tos/copilot-sdk/auth/server-to-server-tokens) | Automatisation attribuée par l’organisation et facturation directe de l’organisation | Aucun abonnement utilisateur ; stratégie d’organisation requise |\n| [BYOK (apportez votre propre clé)](/fr/copilot/how-tos/copilot-sdk/auth/byok)                      | Utilisation de vos propres clés API (Microsoft Foundry, OpenAI, etc.)                | Non                                                             |\n\n## Utilisateur connecté à GitHub\n\nIl s’agit de la méthode d’authentification par défaut lors de l’exécution interactive de l’interface CLI Copilot. Les utilisateurs s’authentifient via le flux d’appareils OAuth de GitHub, et le SDK utilise leurs identifiants enregistrés.\n\n**Fonctionnement :**\n\n1. L’utilisateur exécute `copilot` CLI et se connecte via GitHub OAuth\n2. Les informations d’identification sont stockées de manière sécurisée dans le trousseau de clés du système\n3. Le Kit de développement logiciel (SDK) utilise automatiquement les informations d’identification stockées\n\n**Configuration du Kit de développement logiciel (SDK) :**\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```csharp\nusing GitHub.Copilot;\n\n// Default: uses logged-in user credentials\nawait using CopilotClient client = new();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"go\" data-label=\"Go\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Go</div>\n\n```golang\nimport copilot \"github.com/github/copilot-sdk/go\"\n\n// Default: uses logged-in user credentials\nclient := copilot.NewClient(nil)\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n```java\nimport com.github.copilot.CopilotClient;\n\n// Default: uses logged-in user credentials\nvar client = new CopilotClient();\nclient.start().get();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```python\nfrom copilot import CopilotClient\n\n# Default: uses logged-in user credentials\nclient = CopilotClient()\nawait client.start()\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"rust\" data-label=\"Rust\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Rust</div>\n\n```rust\nuse github_copilot_sdk::{Client, ClientOptions};\n\n// Default: uses logged-in user credentials\nlet client = Client::start(ClientOptions::default()).await?;\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\n// Default: uses logged-in user credentials\nconst client = new CopilotClient();\n```\n\n</div>\n\n</div>\n\n**Quand utiliser :**\n\n* Applications de bureau où les utilisateurs interagissent directement\n* les environnements de développement et de test ;\n* Tout scénario dans lequel un utilisateur peut se connecter de manière interactive\n\n## application OAuth GitHub\n\nUtilisez une application OAuth GitHub pour authentifier les utilisateurs via votre application et transmettre leurs informations d’identification au Kit de développement logiciel (SDK). Cela permet à votre application d’effectuer des requêtes à l’API Copilot pour le compte des utilisateurs qui autorisent votre application.\n\n**Fonctionnement :**\n\n1. L’utilisateur autorise votre application OAuth GitHub\n2. Votre application reçoit un jeton d’accès utilisateur (`gho_` ou `ghu_` préfixe)\n3. Transmettre le jeton au Kit de développement logiciel (SDK) par le biais de sa configuration cliente\n\n**Configuration du Kit de développement logiciel (SDK) :**\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```csharp\nusing GitHub.Copilot;\n\nawait using var client = new CopilotClient(new CopilotClientOptions\n{\n    GitHubToken = userAccessToken,     // Token from OAuth flow\n    UseLoggedInUser = false,           // Don't use stored CLI credentials\n});\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"go\" data-label=\"Go\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Go</div>\n\n```golang\nimport copilot \"github.com/github/copilot-sdk/go\"\n\nclient := copilot.NewClient(&copilot.ClientOptions{\n    GitHubToken:       userAccessToken,      // Token from OAuth flow\n    UseLoggedInUser:   copilot.Bool(false),  // Don't use stored CLI credentials\n})\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n<!-- docs-validate: skip -->\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\nvar client = new CopilotClient(new CopilotClientOptions()\n    .setGitHubToken(userAccessToken)  // Token from OAuth flow\n    .setUseLoggedInUser(false)        // Don't use stored CLI credentials\n);\nclient.start().get();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```python\nfrom copilot import CopilotClient\n\nclient = CopilotClient({\n    \"github_token\": user_access_token,  # Token from OAuth flow\n    \"use_logged_in_user\": False,        # Don't use stored CLI credentials\n})\nawait client.start()\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"rust\" data-label=\"Rust\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Rust</div>\n\n```rust\nuse github_copilot_sdk::{Client, ClientOptions};\n\nlet client = Client::start(\n    ClientOptions::default()\n        .with_github_token(user_access_token)\n        .with_use_logged_in_user(false),\n).await?;\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\nconst client = new CopilotClient({\n    gitHubToken: userAccessToken,  // Token from OAuth flow\n    useLoggedInUser: false,        // Don't use stored CLI credentials\n});\n```\n\n</div>\n\n</div>\n\n**Types de jetons pris en charge :**\n\n* `gho_` - Jetons d’accès utilisateur OAuth\n* `ghu_` - jetons d’accès utilisateur de l’application GitHub\n* `github_pat_` - Jetons d’accès personnels à granularité fine\n\n**Non pris en charge :**\n\n* `ghp_` - Jetons d’accès personnels classiques (déconseillés)\n\n**Quand utiliser :**\n\n* Applications web où les utilisateurs se connectent via GitHub\n* Applications SaaS reposant sur Copilot\n* Toute application multi-utilisateur dans laquelle vous devez effectuer des demandes pour le compte de différents utilisateurs\n\nPour plus d’informations, consultez « [configuration de GitHub OAuth](/fr/copilot/how-tos/copilot-sdk/setup/github-oauth) ».\n\n## Variables d’environnement\n\nPour les scénarios d’automatisation, ci/CD et serveur à serveur, vous pouvez vous authentifier à l’aide de variables d’environnement.\n\nPour l’automatisation attribuée par l’organisation qui ne doit pas utiliser le jeton d’accès personnel d’un utilisateur, consultez [Authentification serveur à serveur](/fr/copilot/how-tos/copilot-sdk/auth/server-to-server-tokens).\n\n**Variables d’environnement prises en charge (par ordre de priorité) :**\n\n1. `COPILOT_GITHUB_TOKEN` - Recommandé pour un usage explicite de Copilot\n2. `GH_TOKEN` - compatible avec GitHub CLI\n3. `GITHUB_TOKEN` - compatible avec GitHub Actions\n\n**Fonctionnement :**\n\n1. Définir l’une des variables d’environnement prises en charge avec un jeton valide\n2. Le Kit de développement logiciel (SDK) détecte et utilise automatiquement le jeton\n\n**Configuration du Kit de développement logiciel (SDK) :**\n\nAucune modification du code n’est nécessaire : le SDK détecte automatiquement les variables d’environnement :\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```csharp\nusing GitHub.Copilot;\n\n// Token is read from environment variable automatically\nawait using CopilotClient client = new();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"go\" data-label=\"Go\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Go</div>\n\n```golang\nimport copilot \"github.com/github/copilot-sdk/go\"\n\n// Token is read from environment variable automatically\nclient := copilot.NewClient(nil)\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n```java\nimport com.github.copilot.CopilotClient;\n\n// Token is read from environment variable automatically\nvar client = new CopilotClient();\nclient.start().get();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```python\nfrom copilot import CopilotClient\n\n# Token is read from environment variable automatically\nclient = CopilotClient()\nawait client.start()\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"rust\" data-label=\"Rust\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Rust</div>\n\n```rust\nuse github_copilot_sdk::{Client, ClientOptions};\n\n// Token is read from environment variable automatically\nlet client = Client::start(ClientOptions::default()).await?;\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nimport { CopilotClient } from \"@github/copilot-sdk\";\n\n// Token is read from environment variable automatically\nconst client = new CopilotClient();\n```\n\n</div>\n\n</div>\n\n**Quand utiliser :**\n\n* pipelines CI/CD (GitHub Actions, Jenkins et plus encore)\n* Tests automatisés\n* Applications côté serveur avec des comptes de service\n* Développement lorsque vous ne souhaitez pas utiliser la connexion interactive\n\n## BYOK (apportez votre propre clé)\n\nBYOK vous permet d’utiliser vos propres clés API à partir de fournisseurs de modèles tels que Microsoft Foundry, OpenAI ou Anthropic. Cela contourne entièrement l’authentification GitHub Copilot.\n\n**Principaux avantages :**\n\n* Aucun abonnement GitHub Copilot requis\n* Utiliser des déploiements de modèles d’entreprise\n* Facturation directe avec votre fournisseur de modèles\n* Prise en charge de Microsoft Foundry, d’OpenAI, d’Anthropic et des points de terminaison compatibles avec OpenAI\n\n**Pour plus d’informations, consultez [autoTITLE](/fr/copilot/how-tos/copilot-sdk/auth/byok)**, notamment :\n\n* configuration de Microsoft Foundry\n* Options de configuration du fournisseur\n* Limitations et considérations\n* Exemples de code complets\n\n## Priorité d’authentification\n\nLorsque plusieurs méthodes d’authentification sont disponibles, le SDK les utilise dans cet ordre de priorité :\n\n1. **Explicite `gitHubToken`** - Jeton transmis directement au client du SDK ou à la configuration de session\n2. **Jeton d’API direct** - `GITHUB_COPILOT_API_TOKEN` avec `COPILOT_API_URL`\n3. **Jetons de variable d’environnement** - `COPILOT_GITHUB_TOKEN` → `GH_TOKEN` → `GITHUB_TOKEN`\n4. **Informations d’identification OAuth stockées** - À partir de la connexion CLI précédente `copilot`\n5. **GitHub CLI** - `gh auth` informations d’identification\n\nPour le mode serveur multi-utilisateur, passez un `gitHubToken` par session afin que chaque session s’exécute avec l’identité de GitHub correcte ; consultez [Multilocataire et déploiements de serveurs](/fr/copilot/how-tos/copilot-sdk/setup/multi-tenancy).\n\n## Désactivation de la connexion automatique\n\nPour empêcher le SDK d’utiliser automatiquement les informations d’identification stockées ou `gh` l’authentification CLI, configurez-le pour désactiver le mécanisme de secours de l’utilisateur connecté :\n\n<div class=\"ghd-codetabs\">\n<div class=\"ghd-codetab\" data-lang=\"dotnet\" data-label=\".NET\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">.NET</div>\n\n```csharp\nawait using var client = new CopilotClient(new CopilotClientOptions\n{\n    UseLoggedInUser = false,  // Only use explicit tokens\n});\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"go\" data-label=\"Go\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Go</div>\n\n```golang\nclient := copilot.NewClient(&copilot.ClientOptions{\n    UseLoggedInUser: copilot.Bool(false),  // Only use explicit tokens\n})\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"java\" data-label=\"Java\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Java</div>\n\n```java\nimport com.github.copilot.CopilotClient;\nimport com.github.copilot.rpc.*;\n\nvar client = new CopilotClient(new CopilotClientOptions()\n    .setUseLoggedInUser(false)  // Only use explicit tokens\n);\nclient.start().get();\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"python\" data-label=\"Python\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Python</div>\n\n```python\nclient = CopilotClient({\n    \"use_logged_in_user\": False,  # Only use explicit tokens\n})\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"rust\" data-label=\"Rust\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">Rust</div>\n\n```rust\nuse github_copilot_sdk::{Client, ClientOptions};\n\nlet client = Client::start(\n    ClientOptions::default().with_use_logged_in_user(false),\n).await?;\n```\n\n</div>\n\n<div class=\"ghd-codetab\" data-lang=\"typescript\" data-label=\"TypeScript\"><div class=\"ghd-codetab-fallback-label\" role=\"heading\" aria-level=\"3\">TypeScript</div>\n\n```typescript\nconst client = new CopilotClient({\n    useLoggedInUser: false,  // Only use explicit tokens\n});\n```\n\n</div>\n\n</div>\n\n## Étapes suivantes\n\n* [BYOK (apportez votre propre clé)](/fr/copilot/how-tos/copilot-sdk/auth/byok) - Découvrez comment utiliser vos propres clés API\n* [Créez votre première application avec Copilot](/fr/copilot/how-tos/copilot-sdk/getting-started) - Créez votre première application basée sur Copilot\n* [Utilisation de serveurs MCP avec le SDK GitHub Copilot](/fr/copilot/how-tos/copilot-sdk/features/mcp) - Se connecter à des outils externes"}