Skip to content

Commit

Permalink
accept additional scopes in auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Aug 12, 2020
1 parent f1c0d04 commit e6ae0a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions internal/config/config_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func IsGitHubApp(id string) bool {
return id == "178c6fc778ccc68e1d6a" || id == "4d747ba5675d5d66553f"
}

func AuthFlowWithConfig(cfg Config, hostname, notice string) (string, error) {
token, userLogin, err := authFlow(hostname, notice)
func AuthFlowWithConfig(cfg Config, hostname, notice string, additionalScopes []string) (string, error) {
token, userLogin, err := authFlow(hostname, notice, additionalScopes)
if err != nil {
return "", err
}
Expand All @@ -50,17 +50,20 @@ func AuthFlowWithConfig(cfg Config, hostname, notice string) (string, error) {
return token, nil
}

func authFlow(oauthHost, notice string) (string, string, error) {
func authFlow(oauthHost, notice string, additionalScopes []string) (string, string, error) {
var verboseStream io.Writer
if strings.Contains(os.Getenv("DEBUG"), "oauth") {
verboseStream = os.Stderr
}

minimumScopes := []string{"repo", "read:org", "gist"}
scopes := append(minimumScopes, additionalScopes...)

flow := &auth.OAuthFlow{
Hostname: oauthHost,
ClientID: oauthClientID,
ClientSecret: oauthClientSecret,
Scopes: []string{"repo", "read:org", "gist"},
Scopes: scopes,
WriteSuccessHTML: func(w io.Writer) {
fmt.Fprintln(w, oauthSuccessPage)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func loginRun(opts *LoginOptions) error {
}

if authMode == 0 {
_, err := config.AuthFlowWithConfig(cfg, hostname, "")
_, err := config.AuthFlowWithConfig(cfg, hostname, "", []string{})
if err != nil {
return fmt.Errorf("failed to authenticate via web browser: %w", err)
}
Expand Down

0 comments on commit e6ae0a1

Please sign in to comment.