Skip to content

Commit 4334489

Browse files
committed
GitHub username hint
1 parent 78216c9 commit 4334489

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,17 @@ func main() {
282282
}
283283
}
284284

285+
var authURLSuffix string
286+
if looksLikeGitHub && pairs["username"] != "" && pairs["username"] != "oauth2" {
287+
authURLSuffix = fmt.Sprintf("&login=%s", pairs["username"])
288+
}
289+
285290
if token == nil {
286291
// Generate new token (opens browser, may require user input)
287292
if device {
288293
token, err = getDeviceToken(ctx, c)
289294
} else {
290-
token, err = getToken(ctx, c)
295+
token, err = getToken(ctx, c, authURLSuffix)
291296
}
292297
if err != nil {
293298
log.Fatalln(err)
@@ -377,7 +382,7 @@ var template string = `<!DOCTYPE html>
377382
</body>
378383
</html>`
379384

380-
func getToken(ctx context.Context, c oauth2.Config) (*oauth2.Token, error) {
385+
func getToken(ctx context.Context, c oauth2.Config, authURLSuffix string) (*oauth2.Token, error) {
381386
state := oauth2.GenerateVerifier()
382387
queries := make(chan url.Values)
383388
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -420,6 +425,7 @@ func getToken(ctx context.Context, c oauth2.Config) (*oauth2.Token, error) {
420425
defer server.Close()
421426
verifier := oauth2.GenerateVerifier()
422427
authCodeURL := c.AuthCodeURL(state, oauth2.S256ChallengeOption(verifier))
428+
authCodeURL += authURLSuffix
423429
fmt.Fprintf(os.Stderr, "Please complete authentication in your browser...\n%s\n", authCodeURL)
424430
var open string
425431
switch runtime.GOOS {

0 commit comments

Comments
 (0)