Skip to content

Commit 93bc389

Browse files
author
Ryan Nystrom
authored
Add scopes flag to login
1 parent 02f4946 commit 93bc389

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/cmd/auth/login/login.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type LoginOptions struct {
2727
Interactive bool
2828

2929
Hostname string
30+
Scopes []string
3031
Token string
3132
Web bool
3233
}
@@ -50,6 +51,9 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
5051
5152
Alternatively, pass in a token on standard input by using %[1]s--with-token%[1]s.
5253
The minimum required scopes for the token are: "repo", "read:org".
54+
55+
The --scopes flag accepts a comma separated list of scopes you want your gh credentials to have. If
56+
absent, this command ensures that gh has access to a minimum set of scopes.
5357
`, "`"),
5458
Example: heredoc.Doc(`
5559
# start interactive setup
@@ -104,6 +108,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
104108
}
105109

106110
cmd.Flags().StringVarP(&opts.Hostname, "hostname", "h", "", "The hostname of the GitHub instance to authenticate with")
111+
cmd.Flags().StringSliceVarP(&opts.Scopes, "scopes", "s", nil, "Additional authentication scopes for gh to have")
107112
cmd.Flags().BoolVar(&tokenStdin, "with-token", false, "Read token from standard input")
108113
cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open a browser to authenticate")
109114

@@ -223,7 +228,7 @@ func loginRun(opts *LoginOptions) error {
223228
}
224229

225230
if authMode == 0 {
226-
_, err := authflow.AuthFlowWithConfig(cfg, hostname, "", []string{})
231+
_, err := authflow.AuthFlowWithConfig(cfg, hostname, "", opts.Scopes)
227232
if err != nil {
228233
return fmt.Errorf("failed to authenticate via web browser: %w", err)
229234
}

0 commit comments

Comments
 (0)