Skip to content

feat(provider): add xAI / SuperGrok OAuth (loopback + device-code)#3438

Open
christophacham wants to merge 1 commit into
tailcallhq:mainfrom
christophacham:feat/xai-supergrok-oauth
Open

feat(provider): add xAI / SuperGrok OAuth (loopback + device-code)#3438
christophacham wants to merge 1 commit into
tailcallhq:mainfrom
christophacham:feat/xai-supergrok-oauth

Conversation

@christophacham
Copy link
Copy Markdown

What

Makes the built-in xai provider OAuth-capable, so you can sign in with an xAI / SuperGrok account instead of pasting an API key.

Two OAuth methods are added to the xai entry in the provider catalog, reusing forgecode's existing generic OAuth framework — no new transport code:

  • oauth_code — loopback authorization-code + PKCE (S256) on 127.0.0.1:56121/callback. Routes through the generic OAuthCodeStrategy<StandardHttpProvider>.
  • oauth_device — RFC 8628 device-code flow for headless / SSH / CI. Routes to the plain OAuthDeviceStrategy.
  • api_key kept as a fallback (picker order: oauth_codeoauth_deviceapi_key).

The access token is injected as a plain Bearer by the existing OpenAI-protocol header builder, and the loopback callback server already accepts the pinned 127.0.0.1 redirect — so the change is data-driven (catalog JSON) plus routing/round-trip tests, with zero per-provider Rust logic.

Test it

forge provider login xai

Then pick OAuth Authorization Code (desktop) or OAuth Device Flow (headless).

Tests added

  • Factory dispatch: XAI oauth_code → Standard, oauth_device → Device.
  • provider.json round-trip asserting client_id / URLs / scopes / redirect / extra params.

Make the built-in `xai` provider OAuth-capable by adding `oauth_code` and
`oauth_device` auth methods alongside `api_key` in the provider catalog,
reusing forgecode's existing generic OAuth framework (no new transport code).

- oauth_code: loopback authorization-code + PKCE (S256) on
  127.0.0.1:56121/callback, plan=generic, referrer=forgecode. Routes to
  OAuthCodeStrategy<StandardHttpProvider> via the factory fall-through.
- oauth_device: RFC 8628 device-code (headless/VPS). auth_url is the
  device-authorization endpoint and token_refresh_url is omitted, so the
  factory routes to the plain OAuthDeviceStrategy (not the Copilot hybrid).
  use_pkce=false to match the oauth2 exchange_device_code flow.
- api_key retained as fallback (picker order: oauth_code, oauth_device, api_key).

The bearer is injected by the existing OpenAI-protocol header builder and the
loopback server already accepts a pinned 127.0.0.1 redirect, so no other code
changes are required.

Tests: factory dispatch (XAI OAuthCode->Standard, OAuthDevice->Device) and a
provider.json round-trip asserting client_id/urls/scopes/redirect/extra params.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 2, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added type: feature Brand new functionality, features, pages, workflows, endpoints, etc. type: provider Updates provider.json configuration. labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc. type: provider Updates provider.json configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants