diff options
author | Lukas <lukas@slucky.de> | 2023-02-02 04:10:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 11:10:37 +0800 |
commit | 3f2e7213720c299b3cace485e97584f0b512bcb7 (patch) | |
tree | 1deec86ed9b4ecc7c373f3a3f1935f3807757ec7 | |
parent | 15c035775a9684cf409ec8bf8a082ae5293a03ab (diff) | |
download | gitea-3f2e7213720c299b3cace485e97584f0b512bcb7.tar.gz gitea-3f2e7213720c299b3cace485e97584f0b512bcb7.zip |
Allow setting access token scope by CLI (#22648)
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>
-rw-r--r-- | cmd/admin.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd/admin.go b/cmd/admin.go index a662011f9c..8f8c68f981 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -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, } @@ -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 { |