From 14ce1f99a705d9c8e15a21afa62780f6e888eb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 15 Apr 2020 14:28:07 +0200 Subject: [PATCH] Ask for an additional `read:org` OAuth scope This is to facilitate: - requesting teams for review on `pr create` - allowing `repo create ORG/REPO --team TEAM` --- auth/oauth.go | 10 ++++++++-- context/config_setup.go | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/auth/oauth.go b/auth/oauth.go index dc7a9d085fe..3f9d9ddc441 100644 --- a/auth/oauth.go +++ b/auth/oauth.go @@ -11,6 +11,7 @@ import ( "net/http" "net/url" "os" + "strings" "github.com/cli/cli/pkg/browser" ) @@ -29,6 +30,7 @@ type OAuthFlow struct { Hostname string ClientID string ClientSecret string + Scopes []string WriteSuccessHTML func(io.Writer) VerboseStream io.Writer } @@ -45,11 +47,15 @@ func (oa *OAuthFlow) ObtainAccessToken() (accessToken string, err error) { } port := listener.Addr().(*net.TCPAddr).Port + scopes := "repo" + if oa.Scopes != nil { + scopes = strings.Join(oa.Scopes, " ") + } + q := url.Values{} q.Set("client_id", oa.ClientID) q.Set("redirect_uri", fmt.Sprintf("http://127.0.0.1:%d/callback", port)) - // TODO: make scopes configurable - q.Set("scope", "repo") + q.Set("scope", scopes) q.Set("state", state) startURL := fmt.Sprintf("https://%s/login/oauth/authorize?%s", oa.Hostname, q.Encode()) diff --git a/context/config_setup.go b/context/config_setup.go index 56bdfe55a42..a55b8dfa6a0 100644 --- a/context/config_setup.go +++ b/context/config_setup.go @@ -36,6 +36,7 @@ func setupConfigFile(filename string) (*configEntry, error) { Hostname: oauthHost, ClientID: oauthClientID, ClientSecret: oauthClientSecret, + Scopes: []string{"repo", "read:org"}, WriteSuccessHTML: func(w io.Writer) { fmt.Fprintln(w, oauthSuccessPage) },