Skip to content

feat(opencode): add xAI Grok OAuth (SuperGrok) + device-code login#28557

Merged
rekram1-node merged 5 commits into
anomalyco:devfrom
Jaaneek:feat/xai-oauth-plugin
May 21, 2026
Merged

feat(opencode): add xAI Grok OAuth (SuperGrok) + device-code login#28557
rekram1-node merged 5 commits into
anomalyco:devfrom
Jaaneek:feat/xai-oauth-plugin

Conversation

@Jaaneek
Copy link
Copy Markdown
Contributor

@Jaaneek Jaaneek commented May 21, 2026

Issue for this PR

Closes #28411

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.

Adds two oauth login methods to the xAI provider so SuperGrok subscribers don't need a paid API key, plus keeps API-key entry as the fallback.

  • PKCE → http://127.0.0.1:56121/callback
  • RFC 8628 device-code: for VPS/SSH etc... hosts where the loopback redirect isn't reachable from the user's browser.

How did you verify your code works?

I did run tests and also did test manually

Screenshots / recordings

image image image image

device code:
image

image

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

Adds two OAuth login methods to the xAI provider so SuperGrok subscribers
don't need a paid API key, plus keeps API-key entry as the fallback.

- Browser loopback: PKCE + state + nonce → http://127.0.0.1:56121/callback,
  HTML-escaped error page, single-flight refresh against xAI's rotating
  refresh_token, header non-mutation, JWT exp check on top of the stored
  expires deadline, best-effort persistence.
- RFC 8628 device-code: for VPS / SSH / Docker / WSL / CI hosts where the
  loopback redirect isn't reachable from the user's browser. Honors
  authorization_pending / slow_down per spec with a 3s safety margin and a
  hard expires_in deadline. Defends the polling loop against malformed
  interval / expires_in (NaN, "NaN", negative, 0) by falling back to the
  default — without this a NaN interval would busy-loop the token endpoint
  via setTimeout(_, NaN).
- Permanent log-only error listener on the OAuth callback server after
  listen() succeeds so accept-time failures don't crash the process. Clears
  oauthServer on listen() failure so a port collision doesn't poison the
  next attempt.

Mirrors the patterns the existing Codex plugin uses and matches its
defensive posture on every dimension I could identify.

Verified:
- cd packages/opencode && bun test test/plugin/xai.test.ts → 51 pass, 144
  expectations
- cd packages/opencode && bun typecheck → clean
- Manual on a SuperGrok account: /connect xai → both OAuth methods complete;
  tokens land in auth.json with rotation; expired-deadline auth auto-refreshes
  within the 2-min skew window; binding :56121 externally produces a clean
  error and a subsequent attempt succeeds.
@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

Comment thread packages/opencode/src/plugin/xai.ts
Comment thread packages/opencode/src/plugin/xai.ts Outdated
@rekram1-node rekram1-node merged commit b32debb into anomalyco:dev May 21, 2026
8 checks passed
MyNameIsGMLi pushed a commit to MyNameIsGMLi/opencode that referenced this pull request May 22, 2026
…nomalyco#28557)

Co-authored-by: Jaaneek <Jaaneek@users.noreply.github.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
sdeonvacation added a commit to sdeonvacation/opencode-x-old that referenced this pull request May 22, 2026
rustybret pushed a commit to rustybret/opencode that referenced this pull request May 22, 2026
…nomalyco#28557)

Co-authored-by: Jaaneek <Jaaneek@users.noreply.github.com>
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add xAI/Grok OAuth login support (like Hermes and Openclaw)

2 participants