opencode icon indicating copy to clipboard operation
opencode copied to clipboard

WIP feat: add chatgpt auth login

Open ScriptedAlchemy opened this issue 4 months ago • 4 comments

This pull request enhances the authentication flow for the OpenAI provider in the CLI, giving users a choice between logging in with ChatGPT (OAuth) or using an API key. It also introduces a more robust OAuth login implementation and adds a custom header for requests to the OpenAI API. The most important changes are grouped below:

OpenAI Authentication Improvements:

  • Added a prompt for OpenAI users to choose between signing in with ChatGPT (OAuth) or using an API key during auth login. If "Sign in with ChatGPT" is selected, the new OAuth flow is initiated.
  • Implemented a complete OAuth login flow for OpenAI, including PKCE challenge generation, local callback server, token exchange, and storing both API and refresh tokens.
  • Improved handling for API key authentication, including validation and proper storage of credentials. [1] [2]

Provider Request Customization:

  • Added an originator: "codex_cli_rs" header to all OpenAI API requests to help identify requests coming from this codex (might not be needed, will confirm).

ScriptedAlchemy avatar Sep 06 '25 07:09 ScriptedAlchemy

in china right now so i cannot properly test authenticating in with a new token, but will check it in the office on monday

ScriptedAlchemy avatar Sep 06 '25 07:09 ScriptedAlchemy

Does it allow us to use the pro package quota ?

asafyish avatar Sep 12 '25 17:09 asafyish

I might be missing this in the code, but what about the token refresh logic?

goniz avatar Sep 17 '25 10:09 goniz

This would be nice to have in if it allows to use the Pro quota

shantur avatar Sep 19 '25 23:09 shantur