@@ -317,10 +317,17 @@ func (api *api) postLogin(rw http.ResponseWriter, r *http.Request) {
317
317
})
318
318
}
319
319
320
- // Creates a new API key, used for logging in via the CLI
321
- func (api * api ) postAPIKey (rw http.ResponseWriter , r * http.Request ) {
320
+ // Creates a new session key, used for logging in via the CLI
321
+ func (api * api ) postKeyForUser (rw http.ResponseWriter , r * http.Request ) {
322
+ user := httpmw .UserParam (r )
322
323
apiKey := httpmw .APIKey (r )
323
- userID := apiKey .UserID
324
+
325
+ if user .ID != apiKey .UserID {
326
+ httpapi .Write (rw , http .StatusUnauthorized , httpapi.Response {
327
+ Message : "Keys can only be generated for the authenticated user" ,
328
+ })
329
+ return
330
+ }
324
331
325
332
keyID , keySecret , err := generateAPIKeyIDSecret ()
326
333
if err != nil {
@@ -333,7 +340,7 @@ func (api *api) postAPIKey(rw http.ResponseWriter, r *http.Request) {
333
340
334
341
_ , err = api .Database .InsertAPIKey (r .Context (), database.InsertAPIKeyParams {
335
342
ID : keyID ,
336
- UserID : userID ,
343
+ UserID : apiKey . UserID ,
337
344
ExpiresAt : database .Now ().AddDate (1 , 0 , 0 ), // Expire after 1 year (same as v1)
338
345
CreatedAt : database .Now (),
339
346
UpdatedAt : database .Now (),
0 commit comments