From 6283c67499f7548df5bff7c23a1d1c3cdaf872d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Fri, 16 Apr 2021 10:20:32 -1000 Subject: [PATCH] Ask for a token, not a password According to [this comment][ref], the usage of a password is currently broken but it is possible to pass an access token instead. This access token is then stored in the configuration file, so adjust the message to ask for an access token, tell the user where then can generate a new one, provide the required scope, and do not tell that the value is not stored. [ref]: https://github.com/github/hub/issues/2655#issuecomment-735836048 --- features/authentication.feature | 10 +++++----- github/config.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/authentication.feature b/features/authentication.feature index b379fcc09..5154ec3a5 100644 --- a/features/authentication.feature +++ b/features/authentication.feature @@ -26,7 +26,7 @@ Feature: OAuth authentication When I type "mislav" And I type "kitty" Then the output should contain "github.com username:" - And the output should contain "github.com password for mislav (never stored):" + And the output should contain "github.com access token with scope 'repo' for mislav (generate one at https://github.com/settings/tokens):" And the exit status should be 0 And the file "~/.config/hub" should contain "user: MiSlAv" And the file "~/.config/hub" should contain "oauth_token: OTOKEN" @@ -159,7 +159,7 @@ Feature: OAuth authentication Given $GITHUB_USER is "mislav" And $GITHUB_PASSWORD is "kitty" When I successfully run `hub create` - Then the output should not contain "github.com password for mislav" + Then the output should not contain "github.com access token with scope 'repo' for mislav" And the file "../home/.config/hub" should contain "oauth_token: OTOKEN" Scenario: XDG: legacy config found, credentials from GITHUB_USER & GITHUB_PASSWORD @@ -371,7 +371,7 @@ Feature: OAuth authentication When I type "mislav" And I type "kitty" And I type "112233" - Then the output should contain "github.com password for mislav (never stored):" + Then the output should contain "github.com access token with scope 'repo' for mislav (generate one at https://github.com/settings/tokens):" Then the output should contain "two-factor authentication code:" And the output should not contain "warning: invalid two-factor code" And the exit status should be 0 @@ -429,7 +429,7 @@ Feature: OAuth authentication When I run `hub create` interactively When I type "mislav@example.com" And I type "my pass@phrase ok?" - Then the output should contain "github.com password for mislav@example.com (never stored):" + Then the output should contain "github.com access token with scope 'repo' for mislav@example.com (generate one at https://github.com/settings/tokens):" And the exit status should be 0 And the file "../home/.config/hub" should contain "user: mislav" And the file "../home/.config/hub" should contain "oauth_token: OTOKEN" @@ -457,7 +457,7 @@ Feature: OAuth authentication When I run `hub fork` interactively And I type "mislav" And I type "kitty" - Then the output should contain "git.my.org password for mislav (never stored):" + Then the output should contain "git.my.org access token with scope 'repo' for mislav (generate one at https://git.my.org/settings/tokens):" And the exit status should be 0 And the file "../home/.config/hub" should contain "git.my.org" And the file "../home/.config/hub" should contain "user: mislav" diff --git a/github/config.go b/github/config.go index 6fbf7dc47..2ba26665a 100644 --- a/github/config.go +++ b/github/config.go @@ -165,7 +165,7 @@ func (c *Config) PromptForPassword(host, user string) (pass string) { return } - ui.Printf("%s password for %s (never stored): ", host, user) + ui.Printf("%s access token with scope 'repo' for %s (generate one at https://%s/settings/tokens): ", host, user, host) if ui.IsTerminal(os.Stdin) { if password, err := getPassword(); err == nil { pass = password