Merge pull request #821 from cli/basic-client-auth

Fix gh updater mechanism for unauthenticated users
This commit is contained in:
Nate Smith 2020-04-28 20:15:17 -05:00 committed by GitHub
commit ef5932f6cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -110,20 +110,11 @@ func BasicClient() (*api.Client, error) {
}
opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", Version)))
c, err := config.ParseDefaultConfig()
if err != nil {
return nil, err
if c, err := config.ParseDefaultConfig(); err == nil {
if token, _ := c.Get(defaultHostname, "oauth_token"); token != "" {
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
}
}
token, err := c.Get(defaultHostname, "oauth_token")
if err != nil {
return nil, err
}
if token == "" {
return nil, fmt.Errorf("no oauth_token set in config")
}
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
return api.NewClient(opts...), nil
}