Skip to content

Commit

Permalink
Ask for an additional read:org OAuth scope
Browse files Browse the repository at this point in the history
This is to facilitate:
- requesting teams for review on `pr create`
- allowing `repo create ORG/REPO --team TEAM`
  • Loading branch information
mislav committed Apr 15, 2020
1 parent 82bd7b9 commit 14ce1f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"strings"

"github.com/cli/cli/pkg/browser"
)
Expand All @@ -29,6 +30,7 @@ type OAuthFlow struct {
Hostname string
ClientID string
ClientSecret string
Scopes []string
WriteSuccessHTML func(io.Writer)
VerboseStream io.Writer
}
Expand All @@ -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())
Expand Down
1 change: 1 addition & 0 deletions context/config_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down

0 comments on commit 14ce1f9

Please sign in to comment.