提交 f1657b0b 编写于 作者: J Jingwen Owen Ou

Paginate API authorizations when searching for existing hub token

上级 d1698648
......@@ -120,7 +120,7 @@ Feature: OAuth authentication
And I type "kitty"
Then the output should contain "github.com password for mislav (never stored):"
And the exit status should be 0
And the file "../home/.config/hub" should contain "oauth_token: OTOKEN"
And the file "../home/.config/hub" should contain 'access_token = "OTOKEN"'
Scenario: Credentials from GITHUB_USER & GITHUB_PASSWORD
Given the GitHub API server:
......
......@@ -377,7 +377,7 @@ func (client *Client) CurrentUser() (user *octokit.User, err error) {
}
func (client *Client) FindOrCreateToken(user, password, twoFactorCode string) (token string, err error) {
url, e := octokit.AuthorizationsURL.Expand(nil)
authUrl, e := octokit.AuthorizationsURL.Expand(nil)
if e != nil {
err = &AuthError{e}
return
......@@ -385,7 +385,7 @@ func (client *Client) FindOrCreateToken(user, password, twoFactorCode string) (t
basicAuth := octokit.BasicAuth{Login: user, Password: password, OneTimePassword: twoFactorCode}
c := client.newOctokitClient(basicAuth)
authsService := c.Authorizations(client.requestURL(url))
authsService := c.Authorizations(client.requestURL(authUrl))
if twoFactorCode != "" {
// dummy request to trigger a 2FA SMS since a HTTP GET won't do it
......@@ -398,6 +398,24 @@ func (client *Client) FindOrCreateToken(user, password, twoFactorCode string) (t
return
}
var moreAuths []octokit.Authorization
for result.NextPage != nil {
authUrl, e := result.NextPage.Expand(nil)
if e != nil {
return "", e
}
authUrl, _ = url.Parse(authUrl.RequestURI())
as := c.Authorizations(authUrl)
moreAuths, result = as.All()
if result.HasError() {
err = &AuthError{result.Err}
return
}
auths = append(auths, moreAuths...)
}
for _, auth := range auths {
if auth.Note == OAuthAppName || auth.NoteURL == OAuthAppURL {
token = auth.Token
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册