You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
createAccessTokenMessage:=fmt.Sprintf("\n"+`🛠 To fix: Create an access token by going to %s/user/settings/tokens, then set the following environment variables in your terminal:
To verify that it's working, run the login command again.
115
-
116
-
Alternatively, you can try logging in using OAuth by running: src login --oauth %s
117
-
`, endpointArg, endpointArg, endpointArg)
99
+
const (
100
+
loginFlowOAuthloginFlowKind=iota
101
+
loginFlowMissingAuth
102
+
loginFlowEndpointConflict
103
+
loginFlowValidate
104
+
)
118
105
119
-
ifcfg.ConfigFilePath!="" {
120
-
fmt.Fprintln(out)
121
-
fmt.Fprintf(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", cfg.ConfigFilePath)
122
-
}
106
+
varloadStoredOAuthToken=oauth.LoadToken
123
107
124
-
noToken:=cfg.AccessToken==""
125
-
endpointConflict:=endpointArg!=cfg.Endpoint
126
-
if!p.useOAuth&& (noToken||endpointConflict) {
127
-
fmt.Fprintln(out)
128
-
switch {
129
-
casenoToken:
130
-
printProblem("No access token is configured.")
131
-
caseendpointConflict:
132
-
printProblem(fmt.Sprintf("The configured endpoint is %s, not %s.", cfg.Endpoint, endpointArg))
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)
printProblem(fmt.Sprintf("Error communicating with %s: %s", endpointArg, err))
172
-
}
173
-
fmt.Fprintln(out, createAccessTokenMessage)
174
-
fmt.Fprintln(out, " (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)")
175
-
returncmderrors.ExitCode1
122
+
ifp.useOAuth {
123
+
returnloginFlowOAuth, runOAuthLogin
176
124
}
177
-
178
-
ifresult.CurrentUser==nil {
179
-
// This should never happen; we verified there is an access token, so there should always be
180
-
// a user.
181
-
printProblem(fmt.Sprintf("Unable to determine user on %s.", endpointArg))
182
-
returncmderrors.ExitCode1
125
+
if!hasEffectiveAuth(ctx, p.cfg, endpointArg) {
126
+
returnloginFlowMissingAuth, runMissingAuthLogin
183
127
}
184
-
fmt.Fprintln(out)
185
-
fmt.Fprintf(out, "✔️ Authenticated as %s on %s\n", result.CurrentUser.Username, endpointArg)
186
-
187
-
ifp.useOAuth {
188
-
fmt.Fprintln(out)
189
-
fmt.Fprintf(out, "Authenticated with OAuth credentials")
returnfmt.Sprintf("\n"+`🛠 To fix: Create an access token by going to %s/user/settings/tokens, then set the following environment variables in your terminal:
225
154
226
-
token:=resp.Token(endpoint)
227
-
token.ClientID=client.ClientID()
228
-
returntoken, nil
229
-
}
155
+
export SRC_ENDPOINT=%s
156
+
export SRC_ACCESS_TOKEN=(your access token)
230
157
231
-
funcopenInBrowser(urlstring) error {
232
-
ifurl=="" {
233
-
returnnil
234
-
}
158
+
To verify that it's working, run the login command again.
235
159
236
-
varcmd*exec.Cmd
237
-
switchruntime.GOOS {
238
-
case"darwin":
239
-
cmd=exec.Command("open", url)
240
-
case"windows":
241
-
// "start" is a cmd.exe built-in; the empty string is the window title.
242
-
cmd=exec.Command("cmd", "/c", "start", "", url)
243
-
default:
244
-
cmd=exec.Command("xdg-open", url)
245
-
}
246
-
returncmd.Run()
160
+
Alternatively, you can try logging in using OAuth by running: src login --oauth %s
0 commit comments