Skip to content

Commit 51440fb

Browse files
committed
remove oauth flag
1 parent ec5f4b1 commit 51440fb

File tree

4 files changed

+6
-30
lines changed

4 files changed

+6
-30
lines changed

cmd/src/login.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ Examples:
2929
3030
$ src login https://sourcegraph.com
3131
32-
Use OAuth device flow to authenticate:
32+
If no access token is configured, 'src login' uses OAuth device flow automatically:
3333
34-
$ src login --oauth https://sourcegraph.com
35-
36-
37-
Override the default client id used during device flow when authenticating:
38-
39-
$ src login --oauth https://sourcegraph.com
34+
$ src login https://sourcegraph.com
4035
`
4136

4237
flagSet := flag.NewFlagSet("login", flag.ExitOnError)
@@ -47,7 +42,6 @@ Examples:
4742

4843
var (
4944
apiFlags = api.NewFlags(flagSet)
50-
useOAuth = flagSet.Bool("oauth", false, "Use OAuth device flow to obtain an access token interactively")
5145
)
5246

5347
handler := func(args []string) error {
@@ -69,7 +63,6 @@ Examples:
6963
client: client,
7064
endpoint: endpoint,
7165
out: os.Stdout,
72-
useOAuth: *useOAuth,
7366
apiFlags: apiFlags,
7467
oauthClient: oauth.NewClient(oauth.DefaultClientID),
7568
})
@@ -87,7 +80,6 @@ type loginParams struct {
8780
client api.Client
8881
endpoint string
8982
out io.Writer
90-
useOAuth bool
9183
apiFlags *api.Flags
9284
oauthClient oauth.Client
9385
}
@@ -117,10 +109,6 @@ func loginCmd(ctx context.Context, p loginParams) error {
117109
func selectLoginFlow(_ context.Context, p loginParams) (loginFlowKind, loginFlow) {
118110
endpointArg := cleanEndpoint(p.endpoint)
119111

120-
if p.useOAuth {
121-
return loginFlowOAuth, runOAuthLogin
122-
}
123-
124112
switch p.cfg.AuthMode() {
125113
case AuthModeOAuth:
126114
return loginFlowOAuth, runOAuthLogin
@@ -146,6 +134,6 @@ func loginAccessTokenMessage(endpoint string) string {
146134
147135
To verify that it's working, run the login command again.
148136
149-
Alternatively, you can try logging in using OAuth by running: src login --oauth %s
137+
Alternatively, you can try logging in interactively by running: src login %s
150138
`, endpoint, endpoint, endpoint)
151139
}

cmd/src/login_oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func oauthLoginClient(ctx context.Context, p loginParams, endpoint string) (api.
4444
}
4545

4646
return api.NewClient(api.ClientOpts{
47-
Endpoint: p.cfg.Endpoint,
47+
Endpoint: endpoint,
4848
AdditionalHeaders: p.cfg.AdditionalHeaders,
4949
Flags: p.apiFlags,
5050
Out: p.out,

cmd/src/login_test.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestLogin(t *testing.T) {
7474
if err != cmderrors.ExitCode1 {
7575
t.Fatal(err)
7676
}
77-
wantOut := "❌ Problem: Invalid access token.\n\n🛠 To fix: Create an access token by going to $ENDPOINT/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=$ENDPOINT\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again.\n\n Alternatively, you can try logging in using OAuth by running: src login --oauth $ENDPOINT\n\n (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)"
77+
wantOut := "❌ Problem: Invalid access token.\n\n🛠 To fix: Create an access token by going to $ENDPOINT/user/settings/tokens, then set the following environment variables in your terminal:\n\n export SRC_ENDPOINT=$ENDPOINT\n export SRC_ACCESS_TOKEN=(your access token)\n\n To verify that it's working, run the login command again.\n\n Alternatively, you can try logging in interactively by running: src login $ENDPOINT\n\n (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)"
7878
wantOut = strings.ReplaceAll(wantOut, "$ENDPOINT", endpoint)
7979
if out != wantOut {
8080
t.Errorf("got output %q, want %q", out, wantOut)
@@ -125,18 +125,6 @@ func (f fakeOAuthClient) Refresh(context.Context, *oauth.Token) (*oauth.TokenRes
125125
}
126126

127127
func TestSelectLoginFlow(t *testing.T) {
128-
t.Run("uses oauth flow when oauth flag is set", func(t *testing.T) {
129-
params := loginParams{
130-
cfg: &config{Endpoint: "https://example.com"},
131-
endpoint: "https://example.com",
132-
useOAuth: true,
133-
}
134-
135-
if got, _ := selectLoginFlow(context.Background(), params); got != loginFlowOAuth {
136-
t.Fatalf("flow = %v, want %v", got, loginFlowOAuth)
137-
}
138-
})
139-
140128
t.Run("uses oauth flow when no access token is configured", func(t *testing.T) {
141129
params := loginParams{
142130
cfg: &config{Endpoint: "https://example.com"},

internal/api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (r *request) do(ctx context.Context, result any) (bool, error) {
269269
if oauth.IsOAuthTransport(r.client.httpClient.Transport) {
270270
fmt.Println("The OAuth token is invalid. Please check that the Sourcegraph CLI client is still authorized.")
271271
fmt.Println("")
272-
fmt.Printf("To re-authorize, run: src login --oauth %s\n", r.client.opts.Endpoint)
272+
fmt.Printf("To re-authorize, run: src login %s\n", r.client.opts.Endpoint)
273273
fmt.Println("")
274274
fmt.Println("Learn more at https://github.com/sourcegraph/src-cli#readme")
275275
fmt.Println("")

0 commit comments

Comments
 (0)