X Tutup
Skip to content

Commit e6ae0a1

Browse files
committed
accept additional scopes in auth flow
1 parent f1c0d04 commit e6ae0a1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

internal/config/config_setup.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func IsGitHubApp(id string) bool {
2626
return id == "178c6fc778ccc68e1d6a" || id == "4d747ba5675d5d66553f"
2727
}
2828

29-
func AuthFlowWithConfig(cfg Config, hostname, notice string) (string, error) {
30-
token, userLogin, err := authFlow(hostname, notice)
29+
func AuthFlowWithConfig(cfg Config, hostname, notice string, additionalScopes []string) (string, error) {
30+
token, userLogin, err := authFlow(hostname, notice, additionalScopes)
3131
if err != nil {
3232
return "", err
3333
}
@@ -50,17 +50,20 @@ func AuthFlowWithConfig(cfg Config, hostname, notice string) (string, error) {
5050
return token, nil
5151
}
5252

53-
func authFlow(oauthHost, notice string) (string, string, error) {
53+
func authFlow(oauthHost, notice string, additionalScopes []string) (string, string, error) {
5454
var verboseStream io.Writer
5555
if strings.Contains(os.Getenv("DEBUG"), "oauth") {
5656
verboseStream = os.Stderr
5757
}
5858

59+
minimumScopes := []string{"repo", "read:org", "gist"}
60+
scopes := append(minimumScopes, additionalScopes...)
61+
5962
flow := &auth.OAuthFlow{
6063
Hostname: oauthHost,
6164
ClientID: oauthClientID,
6265
ClientSecret: oauthClientSecret,
63-
Scopes: []string{"repo", "read:org", "gist"},
66+
Scopes: scopes,
6467
WriteSuccessHTML: func(w io.Writer) {
6568
fmt.Fprintln(w, oauthSuccessPage)
6669
},

pkg/cmd/auth/login/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func loginRun(opts *LoginOptions) error {
210210
}
211211

212212
if authMode == 0 {
213-
_, err := config.AuthFlowWithConfig(cfg, hostname, "")
213+
_, err := config.AuthFlowWithConfig(cfg, hostname, "", []string{})
214214
if err != nil {
215215
return fmt.Errorf("failed to authenticate via web browser: %w", err)
216216
}

0 commit comments

Comments
 (0)
X Tutup