From a80152890cd3db27c25717fdc45ae19b5b2d5b8c Mon Sep 17 00:00:00 2001 From: Ellis Clayton Date: Mon, 19 Apr 2021 10:21:11 +1000 Subject: [PATCH] Support new GitHub token formats GitHub have introduced a new format for their access tokens, which does not fit within the rules of the previous regex. For the time being, the previous token format is still being supported by GitHub, so it makes sense to continue allowing legacy tokens. https://github.blog/changelog/2021-03-04-authentication-token-format-updates/ --- bridge/github/config.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bridge/github/config.go b/bridge/github/config.go index 1e23c8ee5128d55862a46cb137fa7a4a1b1d47c5..55a09c5375d0a75e6a2e1e2658f9fd429b81e804 100644 --- a/bridge/github/config.go +++ b/bridge/github/config.go @@ -365,12 +365,13 @@ func promptToken() (*auth.Token, error) { fmt.Println(" - 'repo' : to be able to read private repositories") fmt.Println() - re := regexp.MustCompile(`^[a-zA-Z0-9]{40}$`) + legacyRe := regexp.MustCompile(`^[a-zA-Z0-9]{40}$`) + re := regexp.MustCompile(`^(?:ghp|gho|ghu|ghs|ghr)_[a-zA-Z0-9]{36,255}$`) var login string validator := func(name string, value string) (complaint string, err error) { - if !re.MatchString(value) { + if !re.MatchString(value) && !legacyRe.MatchString(value) { return "token has incorrect format", nil } login, err = getLoginFromToken(auth.NewToken(target, value))