File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -57,17 +57,28 @@ func runGenerateAccessToken(c *cli.Context) error {
57
57
return err
58
58
}
59
59
60
- accessTokenScope , err := auth_model .AccessTokenScope (c .String ("scopes" )).Normalize ()
60
+ // construct token with name and user so we can make sure it is unique
61
+ t := & auth_model.AccessToken {
62
+ Name : c .String ("token-name" ),
63
+ UID : user .ID ,
64
+ }
65
+
66
+ exist , err := auth_model .AccessTokenByNameExists (t )
61
67
if err != nil {
62
68
return err
63
69
}
70
+ if exist {
71
+ return fmt .Errorf ("access token name has been used already" )
72
+ }
64
73
65
- t := & auth_model. AccessToken {
66
- Name : c .String ("token-name" ),
67
- UID : user . ID ,
68
- Scope : accessTokenScope ,
74
+ // make sure the scopes are valid
75
+ accessTokenScope , err := auth_model . AccessTokenScope ( c .String ("scopes" )). Normalize ()
76
+ if err != nil {
77
+ return fmt . Errorf ( "invalid access token scope provided: %w" , err )
69
78
}
79
+ t .Scope = accessTokenScope
70
80
81
+ // create the token
71
82
if err := auth_model .NewAccessToken (t ); err != nil {
72
83
return err
73
84
}
You can’t perform that action at this time.
0 commit comments