Skip to content

refactor: login cmd#1268

Merged
burmudar merged 1 commit intomainfrom
wb/refactor-login-flows
Mar 9, 2026
Merged

refactor: login cmd#1268
burmudar merged 1 commit intomainfrom
wb/refactor-login-flows

Conversation

@burmudar
Copy link
Contributor

@burmudar burmudar commented Mar 9, 2026

  • split login into distinct flows
  • add specific flow for oauth
  • add specific flows for error conditions
  • update tests

Part of CPL-257

Test plan

Unit tests

@burmudar burmudar self-assigned this Mar 9, 2026
if !p.useOAuth && (noToken || endpointConflict) {
fmt.Fprintln(out)
switch {
case noToken:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This branch was moved to login_validate.go-> runMissingAuthLogin

fmt.Fprintf(p.out, "⚠️ Warning: Configuring src with a JSON file is deprecated. Please migrate to using the env vars SRC_ENDPOINT, SRC_ACCESS_TOKEN, and SRC_PROXY instead, and then remove %s. See https://github.com/sourcegraph/src-cli#readme for more information.\n", p.cfg.ConfigFilePath)
}

if p.useOAuth {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to login_oauth.go -> runOAuthDeviceFlow

endpointArg := cleanEndpoint(p.endpoint)

// See if the user is already authenticated.
query := `query CurrentUser { currentUser { username } }`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to login_validate.go -> runValidateLogin

@burmudar burmudar marked this pull request as ready for review March 9, 2026 12:05
@burmudar burmudar requested a review from a team March 9, 2026 12:06
@burmudar
Copy link
Contributor Author

burmudar commented Mar 9, 2026

Found a minor issue while testing against s2

EDIT: It was against dotCom, and it works against S2

go run ./cmd/src login --oauth

If your browser did not open automatically, visit https://sourcegraph.sourcegraph.com/auth/device?user_code=*****.
Waiting for authorization... DONE


✔︎ Authenticated as william.bezuidenhout on https://sourcegraph.sourcegraph.com


✔︎ Authenticated with OAuth credentials

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

nice stuff. Just did loads of testing with --oauth and its working well.

- split login into distinct flows
- add specific flow for oauth
- add specific flows for error conditions
- update tests
@burmudar burmudar force-pushed the wb/refactor-login-flows branch from eb8f159 to ec66359 Compare March 9, 2026 14:33
@burmudar burmudar merged commit c6de254 into main Mar 9, 2026
8 checks passed
@burmudar burmudar deleted the wb/refactor-login-flows branch March 9, 2026 14:41
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