Skip to content

Commit

Permalink
Allow setting access token scope by CLI (#22648)
Browse files Browse the repository at this point in the history
Followup for #20908 to allow setting the scopes when creating new access
token via CLI.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
  • Loading branch information
3 people authored Feb 2, 2023
1 parent 15c0357 commit 3f2e721
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ var (
Name: "raw",
Usage: "Display only the token value",
},
cli.StringFlag{
Name: "scopes",
Value: "",
Usage: "Comma separated list of scopes to apply to access token",
},
},
Action: runGenerateAccessToken,
}
Expand Down Expand Up @@ -698,9 +703,15 @@ func runGenerateAccessToken(c *cli.Context) error {
return err
}

accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize()
if err != nil {
return err
}

t := &auth_model.AccessToken{
Name: c.String("token-name"),
UID: user.ID,
Name: c.String("token-name"),
UID: user.ID,
Scope: accessTokenScope,
}

if err := auth_model.NewAccessToken(t); err != nil {
Expand Down

0 comments on commit 3f2e721

Please sign in to comment.