X Tutup
Skip to content

feat: dynamically start oauth flow if no SRC_ACCESS_TOKEN#1271

Merged
burmudar merged 6 commits intomainfrom
wb/dynamic-oauth
Mar 10, 2026
Merged

feat: dynamically start oauth flow if no SRC_ACCESS_TOKEN#1271
burmudar merged 6 commits intomainfrom
wb/dynamic-oauth

Conversation

@burmudar
Copy link
Contributor

@burmudar burmudar commented Mar 10, 2026

  • Remove the --oauth flag
  • Add AuthMode on config to determine what flow we should run from config
  • If CI=1 SRC_ACCESS_TOKEN is required

Closes CPL-257

Test plan

Unit tests + manual tests

# OAuth stored in keychain
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; echo 'query { currentUser { username } }' | go run ./cmd/src api
{
  "data": {
    "currentUser": {
      "username": "william.bezuidenhout"
    }
  }
}
❯ export CI=1
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; echo 'query { currentUser { username } }' | go run ./cmd/src api
reading config: SRC_ACCESS_TOKEN must be set in CI
exit status 1
❯ unset CI
❯ export SRC_ACCESS_TOKEN=***
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; echo 'query { currentUser { username } }' | go run ./cmd/src api
{
  "data": {
    "currentUser": {
      "username": "william.bezuidenhout"
    }
  }
}

src-cli on  wb/dynamic-oauth [$?] via 🐹 v1.25.5
❯ export CI=1

src-cli on  wb/dynamic-oauth [$?] via 🐹 v1.25.5
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; echo 'query { currentUser { username } }' | go run ./cmd/src api
{
  "data": {
    "currentUser": {
      "username": "william.bezuidenhout"
    }
  }
}

No OAuth token in keychain

export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; echo 'query { currentUser { username } }' | go run ./cmd/src api
error: 401 Unauthorized

Private mode requires authentication.
exit status 1

burmudar added 2 commits March 9, 2026 20:58
- AuthModeAccessToken and AuthModeOAuth
- And check for CI and required AuthModeAccessToken
@burmudar burmudar self-assigned this Mar 10, 2026
@burmudar burmudar marked this pull request as ready for review March 10, 2026 08:20
@burmudar burmudar requested a review from a team March 10, 2026 08:21
@burmudar burmudar marked this pull request as draft March 10, 2026 10:01
@burmudar
Copy link
Contributor Author

burmudar commented Mar 10, 2026

Found a small regression

src login in OAuth mode would always start the device flow, even though we had a perfectly ok token stored in the secret storage. We now check the storage for a token before starting the flow.

@burmudar burmudar marked this pull request as ready for review March 10, 2026 11:51
@burmudar burmudar merged commit 4c3f356 into main Mar 10, 2026
8 checks passed
@burmudar burmudar deleted the wb/dynamic-oauth branch March 10, 2026 12:50
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.

2 participants

X Tutup