Skip to content

feat/auth: add src auth token#1275

Merged
burmudar merged 3 commits intomainfrom
wb/src-auth
Mar 17, 2026
Merged

feat/auth: add src auth token#1275
burmudar merged 3 commits intomainfrom
wb/src-auth

Conversation

@burmudar
Copy link
Contributor

This adds the command src auth token, which will print either your access token or your oauth token. This is primarily useful for scenarios like curl -H "Authorization: Bearer $(src auth token)" https://sourcegraph.sourcegraph.com/.api/something.

If no SRC_ACCESS_TOKEN is specified and we use the OAuth token and the token is close to expiring or has expired it will be automatically refreshed

  • Centralized the refreshing logic to TokenRefresher which the oauth transport now uses as well as the OAuth token
  • Create a constructor NewTransport so that TokenRefresher is properly initialized for the OAuth.Transport

Closes CPL-274

Future work

  • support src auth status and tell you if we're using SRC_ACCESS_TOKEN or OAuth and with which endpoint

Test plan

src-cli on  wb/src-auth [$?] via 🐹 v1.25.5
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; go run ./cmd/src/... auth token
sgo_at_DEADBEEF

src-cli on  wb/src-auth [$?] via 🐹 v1.25.5 took 2s
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; export SRC_ACCESS_TOKEN='hello-reviewer'; go run ./cmd/src/... auth token
hello-reviewer

When there is no OAuth Token and no SRC_ACCESS_TOKEN

export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com; go run ./cmd/src/... auth token
error loading OAuth token; set SRC_ACCESS_TOKEN or run `src login`: secret not found

- TokenRefresher centralizes refreshing of OAuth tokens
- NewTransport creates an OAuth transport while making sure it is
  initialized with a TokenRefresher
@burmudar burmudar requested review from a team and eseliger March 17, 2026 14:04
@burmudar burmudar self-assigned this Mar 17, 2026
Copy link
Member

@eseliger eseliger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't read all the code but it's a great addition!

@burmudar burmudar enabled auto-merge (squash) March 17, 2026 14:25
@burmudar burmudar merged commit d206288 into main Mar 17, 2026
9 checks passed
@burmudar burmudar deleted the wb/src-auth branch March 17, 2026 14:31
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.

3 participants