Skip to content

fix/login: override config endpoint if endpoint positional argument is given#1300

Merged
burmudar merged 6 commits intomainfrom
wb/src-login-endpoint
Apr 21, 2026
Merged

fix/login: override config endpoint if endpoint positional argument is given#1300
burmudar merged 6 commits intomainfrom
wb/src-login-endpoint

Conversation

@burmudar
Copy link
Copy Markdown
Contributor

@burmudar burmudar commented Apr 20, 2026

Config would default endpoint to https://sourcegraph.com if unset, so when login validated the positional endpoint argument against the config it would be in conflict and then tell the user that the arg they provided conflicts with https://sourcegraph.com, meanwhile they didn't set anything.

We now:

  • override the config endpoint if the endpoint positional arg is set during login
  • detect when the default endpoint is set, SRC_ENDPOINT is not set and and cfg.endpointURL is nil
  • Inform the user when we are not using the configured endpoint and when we're using the default

Closes CPL-359

Test plan

❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com

❯ go run ./cmd/src login

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


✔︎ Authenticated with OAuth credentials

❯ go run ./cmd/src login https://sourcegraph.com
⚠️  Warning: Logging into https://sourcegraph.com instead of the configured endpoint https://sourcegraph.sourcegraph.com.

💡 Tip: To use this endpoint in your shell, run:

   export SRC_ENDPOINT=https://sourcegraph.com

❌ Problem: Error communicating with https://sourcegraph.com: Post "https://sourcegraph.com/.api/graphql": refresh token failed: invalid_grant: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. The refresh token is malformed or not valid.

🛠  To fix: Create an access token by going to https://sourcegraph.com/user/settings/tokens, then set the following environment variables in your terminal:

   export SRC_ENDPOINT=https://sourcegraph.com
   export SRC_ACCESS_TOKEN=(your access token)

   To verify that it's working, run the login command again.

   Alternatively, you can try logging in interactively by running: src login https://sourcegraph.com

   (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md)
exit status 1

❯ export SRC_ENDPOINT=https://sourcegraph.com

❯ go run ./cmd/src login
❌ Problem: Error communicating with https://sourcegraph.com: Post "https://sourcegraph.com/.api/graphql": refresh token failed: invalid_grant: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. The refresh token is malformed or not valid.

🛠  To fix: Create an access token by going to https://sourcegraph.com/user/settings/tokens, then set the following environment variables in your terminal:

   export SRC_ENDPOINT=https://sourcegraph.com
   export SRC_ACCESS_TOKEN=(your access token)

   To verify that it's working, run the login command again.

   Alternatively, you can try logging in interactively by running: src login https://sourcegraph.com

   (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md)
exit status 1

❯ go run ./cmd/src login https://sourcegraph.com
❌ Problem: Error communicating with https://sourcegraph.com: Post "https://sourcegraph.com/.api/graphql": refresh token failed: invalid_grant: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. The refresh token is malformed or not valid.

🛠  To fix: Create an access token by going to https://sourcegraph.com/user/settings/tokens, then set the following environment variables in your terminal:

   export SRC_ENDPOINT=https://sourcegraph.com
   export SRC_ACCESS_TOKEN=(your access token)

   To verify that it's working, run the login command again.

   Alternatively, you can try logging in interactively by running: src login https://sourcegraph.com

   (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md)
exit status 1

❯ go run ./cmd/src login https://sourcegraph.sourcegraph.com
⚠️  Warning: Logging into https://sourcegraph.sourcegraph.com instead of the configured endpoint https://sourcegraph.com.

💡 Tip: To use this endpoint in your shell, run:

   export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com


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


✔︎ Authenticated with OAuth credentials
❯ export SRC_ENDPOINT=https://sourcegraph.sourcegraph.com
❯ go run ./cmd/src login https://sourcegraph.com
⚠️  Warning: Logging into https://sourcegraph.com instead of the configured endpoint https://sourcegraph.sourcegraph.com.

💡 Tip: To use this endpoint in your shell, run:

   export SRC_ENDPOINT=https://sourcegraph.com

❌ Problem: Error communicating with https://sourcegraph.com: Post "https://sourcegraph.com/.api/graphql": refresh token failed: invalid_grant: The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. The refresh token is malformed or not valid.

🛠  To fix: Create an access token by going to https://sourcegraph.com/user/settings/tokens, then set the following environment variables in your terminal:

   export SRC_ENDPOINT=https://sourcegraph.com
   export SRC_ACCESS_TOKEN=(your access token)

   To verify that it's working, run the login command again.

   Alternatively, you can try logging in interactively by running: src login https://sourcegraph.com

   (If you need to supply custom HTTP request headers, see information about SRC_HEADER_* and SRC_HEADERS env vars at https://github.com/sourcegraph/src-cli/blob/main/AUTH_PROXY.md)
exit status 1

- update config endpointURL if endpointURL is set either as a flag or
  positional argument
- warn the user about endpoint conflict or that the default endpoint is
  being used
@burmudar burmudar self-assigned this Apr 20, 2026
@burmudar burmudar force-pushed the wb/src-login-endpoint branch 2 times, most recently from 32c7289 to 131ac9a Compare April 20, 2026 11:33
@burmudar burmudar requested a review from a team April 20, 2026 11:34
@burmudar burmudar marked this pull request as ready for review April 20, 2026 11:34
@burmudar burmudar force-pushed the wb/src-login-endpoint branch from 131ac9a to 89f7c8f Compare April 21, 2026 08:25
@burmudar burmudar merged commit fd61054 into main Apr 21, 2026
9 checks passed
@burmudar burmudar deleted the wb/src-login-endpoint branch April 21, 2026 09:53
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