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