Skip to content

Commit b85a5fc

Browse files
fixup! feat(security): application token refresh
add missing userid check
1 parent 89e1968 commit b85a5fc

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

‎api/application.go‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,20 +335,22 @@ func (a *ApplicationAPI) UpdateApplicationSecurity(ctx *gin.Context) {
335335
if success := successOrAbort(ctx, 500, err); !success {
336336
return
337337
}
338-
action := model.SecurityUpdateAction{}
339-
response := model.SecurityUpdateActionResponse{}
340-
if err := ctx.Bind(&action); err == nil {
341-
if action.RegenerateToken {
342-
tokenPublic, tokenPrivate := generateApplicationToken()
343-
app.Token = tokenPublic
344-
response.RegenerateToken = &model.RegenerateTokenResponse{
345-
Token: tokenPrivate,
338+
if app != nil && app.UserID == auth.GetUserID(ctx) {
339+
action := model.SecurityUpdateAction{}
340+
response := model.SecurityUpdateActionResponse{}
341+
if err := ctx.Bind(&action); err == nil {
342+
if action.RegenerateToken {
343+
tokenPublic, tokenPrivate := generateApplicationToken()
344+
app.Token = tokenPublic
345+
response.RegenerateToken = &model.RegenerateTokenResponse{
346+
Token: tokenPrivate,
347+
}
346348
}
349+
if success := successOrAbort(ctx, 500, a.DB.UpdateApplication(app)); !success {
350+
return
351+
}
352+
ctx.JSON(200, response)
347353
}
348-
if success := successOrAbort(ctx, 500, a.DB.UpdateApplication(app)); !success {
349-
return
350-
}
351-
ctx.JSON(200, response)
352354
}
353355
})
354356
}

0 commit comments

Comments
 (0)