{"meta":{"title":"Server-zu-Server-Authentifizierung","intro":"Verwenden Sie ein kurzlebiges Installationszugriffstoken, wenn ein Dienst Copilot Anforderungen im Namen einer Organisation ohne Anmeldeinformationen eines Benutzers vornehmen muss. Verwenden Sie in GitHub Actions stattdessen die integrierte GITHUB_TOKEN Datei.","product":"GitHub Copilot","breadcrumbs":[{"href":"/de/copilot","title":"GitHub Copilot"},{"href":"/de/copilot/how-tos","title":"Vorgehensweisen"},{"href":"/de/copilot/how-tos/copilot-sdk","title":"Copilot SDK"},{"href":"/de/copilot/how-tos/copilot-sdk/auth","title":"Authentication"},{"href":"/de/copilot/how-tos/copilot-sdk/auth/server-to-server-tokens","title":"Server-zu-Server-Token"}],"documentType":"article"},"body":"# Server-zu-Server-Authentifizierung\n\nVerwenden Sie ein kurzlebiges Installationszugriffstoken, wenn ein Dienst Copilot Anforderungen im Namen einer Organisation ohne Anmeldeinformationen eines Benutzers vornehmen muss. Verwenden Sie in GitHub Actions stattdessen die integrierte GITHUB_TOKEN Datei.\n\n<!-- markdownlint-disable GHD046 GHD005 -->\n\n<!-- Suppressed: GHD046 (outdated release terminology), GHD005 (hardcoded data variable) -->\n\n## GitHub Actions\n\nErteilen Sie für Workflows in einem organisationseigenen Repository die integrierte Tokenberechtigung, um Copilot Anforderungen zu stellen:\n\n```yaml\npermissions:\n  contents: read\n  copilot-requests: write\n\njobs:\n  copilot:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v6\n      - run: your-application\n        env:\n          GITHUB_TOKEN: $\n```\n\nDie **zulassungsfähige Verwendung von Copilot CLI, die der Organisationsrichtlinie in Rechnung gestellt** wird, muss aktiviert sein. Dieser Ansatz benötigt keinen GitHub App- oder gespeicherten Authentifizierungsschlüssel. Ausführliche Informationen findest du unter [Verwenden von Copilot CLI in GitHub Actions mit GITHUB\\_TOKEN](/de/copilot/how-tos/copilot-cli/use-copilot-cli-in-actions).\n\n## Andere Dienstleistungen und CI-Systeme\n\nFür Dienste außerhalb GitHub Actions:\n\n1. Erstellen Sie eine GitHub App mit der <c0>Copilot</c0> Anforderungs-Repositoryberechtigung auf <c1>Lese-& Schreibzugriff</c1>.\n\n2. Installieren Sie sie in der Organisation, die in Rechnung gestellt werden soll. Die aktuelle Copilot Berechtigungsprüfung erfordert Zugriff auf **alle Repositorys**.\n\n3. [Generieren eines Installationszugriffstokens für eine GitHub App](/de/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app) mit einer Repository-ID und der Copilot Berechtigung:\n\n   ```json\n   {\n     \"repository_ids\": [123456789],\n     \"permissions\": {\n       \"copilot_requests\": \"write\"\n     }\n   }\n   ```\n\n4. Übergeben Sie das resultierende `ghs_` Token an die Laufzeit als `COPILOT_GITHUB_TOKEN`.\n\nDie Organisation muss für Copilot Anforderungen von GitHub App-Installationen aktiviert sein. Installationstoken laufen nach einer Stunde ab.\n\n> \\[!WARNING]\n> Übergeben Sie kein Installationstoken über die `gitHubToken`Sdk-Option oder `github_token`die entsprechende Option. Diese Option gilt für Benutzertoken. Installationstoken müssen den Authentifizierungspfad der Laufzeitumgebung verwenden.\n\n## Konfigurieren der Runtime\n\nIn den folgenden Beispielen wird davon ausgegangen, dass das geprägte Token in `INSTALLATION_TOKEN`ist. Sie übergeben es nur an die untergeordnete Laufzeit und deaktivieren Fallback auf gespeicherte Benutzeranmeldeinformationen.\n\n<div class=\"ghd-codetabs\">\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, RuntimeConnection } from \"@github/copilot-sdk\";\n\nconst token = process.env.INSTALLATION_TOKEN;\nif (!token) throw new Error(\"INSTALLATION_TOKEN is required\");\n\nconst client = new CopilotClient({\n    connection: RuntimeConnection.forStdio(),\n    env: {\n        ...process.env,\n        COPILOT_GITHUB_TOKEN: token,\n    },\n    useLoggedInUser: false,\n});\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\nimport os\n\nfrom copilot import CopilotClient, RuntimeConnection\n\nclient = CopilotClient(\n    connection=RuntimeConnection.for_stdio(),\n    env={**os.environ, \"COPILOT_GITHUB_TOKEN\": os.environ[\"INSTALLATION_TOKEN\"]},\n    use_logged_in_user=False,\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\npackage main\n\nimport (\n    \"log\"\n    \"os\"\n\n    copilot \"github.com/github/copilot-sdk/go\"\n)\n\nfunc main() {\n    token, ok := os.LookupEnv(\"INSTALLATION_TOKEN\")\n    if !ok {\n        log.Fatal(\"INSTALLATION_TOKEN is required\")\n    }\n    client := copilot.NewClient(&copilot.ClientOptions{\n        Connection:      copilot.StdioConnection{},\n        Env:             append(os.Environ(), \"COPILOT_GITHUB_TOKEN=\"+token),\n        UseLoggedInUser: copilot.Bool(false),\n    })\n    _ = client\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::{ClientOptions, Transport};\n\nfn main() {\n    let token = std::env::var(\"INSTALLATION_TOKEN\").expect(\"INSTALLATION_TOKEN is required\");\n    let options = ClientOptions::new()\n        .with_transport(Transport::Stdio)\n        .with_env([(\"COPILOT_GITHUB_TOKEN\", token)])\n        .with_use_logged_in_user(false);\n    drop(options);\n}\n```\n\n</div>\n\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 System.Collections;\nusing GitHub.Copilot;\n\nvar token = Environment.GetEnvironmentVariable(\"INSTALLATION_TOKEN\")\n    ?? throw new InvalidOperationException(\"INSTALLATION_TOKEN is required\");\nvar environment = Environment.GetEnvironmentVariables()\n    .Cast<DictionaryEntry>()\n    .ToDictionary(entry => (string)entry.Key, entry => entry.Value?.ToString() ?? \"\");\nenvironment[\"COPILOT_GITHUB_TOKEN\"] = token;\n\nawait using var client = new CopilotClient(new CopilotClientOptions\n{\n    Connection = RuntimeConnection.ForStdio(),\n    Environment = environment,\n    UseLoggedInUser = false,\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.CopilotClientOptions;\nimport java.util.HashMap;\nimport java.util.Objects;\n\nvar environment = new HashMap<>(System.getenv());\nvar token = Objects.requireNonNull(\n    System.getenv(\"INSTALLATION_TOKEN\"), \"INSTALLATION_TOKEN is required\");\nenvironment.put(\"COPILOT_GITHUB_TOKEN\", token);\n\ntry (var client = new CopilotClient(new CopilotClientOptions()\n        .setEnvironment(environment)\n        .setUseLoggedInUser(false))) {\n    // Use the client.\n}\n```\n\n</div>\n\n</div>\n\nLegen Sie für prozessinterne FFI in der Hostumgebung vor dem Laden der Laufzeit fest `COPILOT_GITHUB_TOKEN` . Optionen pro Clientumgebung werden nicht unterstützt. Legen Sie ihn für einen vorhandenen Laufzeit-URI für diesen Laufzeitprozess fest.\n\n## Aktualisierungs-Token\n\nStellen Sie ein neues Installationstoken vor Ablauf des aktuellen Tokens vor. Starten Sie für einen untergeordneten Prozess den SDK-Client mit der neuen Umgebung neu. Starten Sie für eine in-Process- oder vorhandene Laufzeit die Hostlaufzeit mit dem neuen Token neu.\n\n## Billing\n\nDie Verwendung wird dem Konto zugeordnet und in Rechnung gestellt, das die GitHub App-Installation besitzt. Verwenden Sie eine Organisationsinstallation für die Abrechnung der Organisation; Verwendung von Benutzerkontoinstallationsattributen für diesen Benutzer.\n\n## Troubleshooting\n\n| Symptom                                                                                              | Prüfen                                                                                                                             |\n| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |\n| `401 Unauthorized`                                                                                   | Bestätigen Sie, dass die Organisation GitHub App-Installationsauthentifizierung für Copilot unterstützt.                           |\n| `403 Resource not accessible by integration` oder ein Fehler beim Erwähnen von Benutzerinformationen | Bestätigen Sie, dass sich das Installationstoken befindet `COPILOT_GITHUB_TOKEN`, nicht die explizite Tokenoption des SDK.         |\n| `403 Forbidden`aus der Copilot-API                                                                   | Bestätigen Sie, dass die Tokenanforderung enthält `repository_ids` und .`copilot_requests: write`                                  |\n| `403 Forbidden` mit der erforderlichen Tokenanforderung                                              | Vergewissern Sie sich, dass die App-Installation zugriff auf **alle Repositorys** hat, und stellen Sie dann ein neues Token fest.  |\n| Das angeforderte Modell ist nicht verfügbar.                                                         | Vergewissern Sie sich, dass die Copilot-Richtlinie der Organisation das Modell zulässt und die gebündelte Laufzeit es unterstützt. |\n| Falsche Rechnung in Rechnung gestellt                                                                | Bestätigen Sie, dass die Installation zur beabsichtigten Organisation gehört.                                                      |\n\n## Weiterführende Lektüre\n\n* [Authentication](/de/copilot/how-tos/copilot-sdk/auth/authenticate): andere Authentifizierungsmethoden und Priorität\n* [Generieren eines Installationszugriffstokens für eine GitHub App](/de/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app): GitHub App-Tokenerstellung"}