Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting access token scope by CLI #22648

Merged
merged 7 commits into from
Feb 2, 2023
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