Skip to content

Copilot driver auth is broken - requires OAuth device flow token, not PAT #1014

@dmbutko

Description

@dmbutko

Description

The GitHub Copilot LLM driver does not work with any standard GitHub token type. The code says it exchanges a GitHub PAT for a Copilot API token, but the copilot_internal/v2/token endpoint rejects all standard token types:

  • Classic PATs (ghp_) - 403 Forbidden
  • Fine-grained PATs (github_pat_) with Copilot permission - 403 Forbidden
  • gh CLI OAuth tokens (gho_) with copilot scope - 404 Not Found

The only token type that works is a ghu_ token obtained via the OAuth device flow using the VS Code Copilot extension's client ID (Iv1.b507a08c87ecfe98). There is no way for users to generate this through the GitHub website or standard tooling.

Reproduction

  1. Install OpenFang, configure github-copilot provider with any standard token
  2. Any chat or message attempt fails with 403 or 404 on token exchange

Working workaround

Manually run the OAuth device flow:

curl -s -X POST -H "Accept: application/json" \
  -d "client_id=Iv1.b507a08c87ecfe98&scope=copilot" \
  https://github.com/login/device/code
# authorize at github.com/login/device
curl -s -X POST -H "Accept: application/json" \
  -d "client_id=Iv1.b507a08c87ecfe98&device_code=DEVICE_CODE&grant_type=urn:ietf:params:oauth:grant-type:device_code" \
  https://github.com/login/oauth/access_token

This returns a ghu_ token that works. But it is short-lived and requires manual renewal.

Additional issue

Default config sets model to copilot/gpt-4 which returns model_not_supported. The API expects bare names like gpt-4o or claude-sonnet-4.6.

Proposed fix

  1. Implement OAuth device flow directly in the driver
  2. Auto-refresh the ghu_ token before expiry
  3. openfang config set-key github-copilot should trigger the device flow
  4. openfang doctor should check GITHUB_TOKEN when Copilot provider is configured
  5. Default model names should use bare names not prefixed ones

Environment

  • OpenFang v0.5.5
  • Linux Debian amd64
  • Copilot Enterprise
  • Source: crates/openfang-runtime/src/drivers/copilot.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions