Skip to content

Opencode not handling expired refresh_tokens #13998

Closed

Description

@GreenStage

Description

The current implementation of the OAuth client does not gracefully handle an invalid_grant error response from the /token endpoint. When the authorization server returns a 400 Bad Request with error: "invalid_grant", the client remains in an unauthenticated state without triggering a new authorization flow.

From RFC 6749 § 5.2

invalid_grant
The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked... The authorization server responds with an HTTP 400 (Bad Request)

Opencode does not handle this and remains in a error state, until users manually have to logout and auth again.
Instead, it should start a new authorization flow through the browser

Plugins

No response

OpenCode version

1.2.6

Steps to reproduce

  1. Setup a MCP server with oauth that returns refresh_tokens that are valid for 5m, and access tokens valid for 1m.
  2. Add this mcp server to opencode
  3. opencode mcp auth and complete the initial authorization flow
  4. wait 6 minutes
  5. opencode mcp auth, server credentials show as expired. When saying OK to reauthenticate, it fails as the refresh token has expired.

Screenshot and/or share link

Image

Operating System

Linux x64

Terminal

gnome terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 17, 2026
  2. github-actions commented on Feb 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or related to existing issues. Please check:

    Both issues involve the opencode mcp auth command failing during reauthentication scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions