Skip to content

feat(opencode): add Snowflake Cortex SSO (external browser) authentication#31703

Closed
davidfierro wants to merge 1 commit into
anomalyco:devfrom
davidfierro:feat/snowflake-cortex-sso
Closed

feat(opencode): add Snowflake Cortex SSO (external browser) authentication#31703
davidfierro wants to merge 1 commit into
anomalyco:devfrom
davidfierro:feat/snowflake-cortex-sso

Conversation

@davidfierro

Copy link
Copy Markdown

Issue for this PR

Closes #31702

Type of change

  • New feature

What does this PR do?

Snowflake Cortex previously only supported PAT auth. This adds SSO via the external browser flow, so users on accounts with an external IdP can log in without a token.

It replicates the Snowflake driver EXTERNALBROWSER handshake: POST /session/authenticator-request → open the browser → capture the IdP token on a local 127.0.0.1 loopback → POST /session/v1/login-request to get a session + master token. The custom fetch sends Authorization: Snowflake Token="<session>" (the format the Cortex REST API actually accepts — Bearer is rejected, verified against a live account) and transparently renews the session token via /session/token-request when it nears expiry. When the master token expires the user is asked to log in again.

SSO is selectable from both opencode auth login (PAT | SSO) and the TUI /connect dialog. PAT auth is unchanged.

How did you verify your code works?

  • Unit tests (run from packages/opencode and packages/core):
    • the auth schema round-trips the new snowflake-session credential
    • the external-browser module: session-token renewal request shape, the Snowflake Token header injection, single-flight renewal under concurrent requests, and the master-token-expired error path
    • the /connect plugin exposes PAT + SSO methods and persists a snowflake-session credential identical to the CLI path
    • the provider appears in the model list (with its catalog models) when an SSO or PAT credential is stored, and is absent with none
    • the V2 provider plugin passes the SSO fetch through unchanged
  • Manual: bun dev, /connect → Snowflake Cortex → SSO, completed the IdP login in the browser, confirmed the model picker lists the Cortex models and a chat request streams successfully; confirmed PAT login still works.

Screenshots / recordings

TUI change — /connect now shows a PAT/SSO method selector for Snowflake Cortex. Happy to attach a recording if useful.

Checklist

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

…ation

Add SSO via the Snowflake external-browser flow alongside the existing PAT
auth. Replicates the driver handshake (authenticator-request -> loopback ->
login-request), sends the session token with the `Snowflake Token` header the
Cortex REST API accepts, and renews it automatically. Selectable from both
`auth login` and the TUI `/connect` dialog; PAT auth is unchanged.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potential duplicate:

PR #31700 - feat(opencode): add external browser OAuth for snowflake cortex provider
#31700

This PR appears to address the same feature: adding external browser OAuth/SSO authentication for Snowflake Cortex. It likely implements the same EXTERNALBROWSER handshake flow and IdP token capture mechanism that PR #31703 adds.

@davidfierro

Copy link
Copy Markdown
Author

Closing the PR as it's duplicated with #31700

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Snowflake Cortex SSO (external browser) authentication

1 participant