fix(api-keys): harden scoped key auth after code review
Revoke existing keys on reset, unify scope enforcement, default empty scopes to read-only, map API key scopes to tenant roles, and remove dead key-generation helpers left over from the tenant api_key column removal.
This commit is contained in:
@@ -537,7 +537,7 @@ func (h *TenantHandler) UpdateTenant(c *gin.Context) {
|
||||
|
||||
// ResetAPIKey godoc
|
||||
// @Summary 重置租户 API Key
|
||||
// @Description 为指定租户生成一个新的 API Key,旧 Key 立即失效
|
||||
// @Description 吊销该租户全部现有 API Key 后创建一把新的全权限 Key
|
||||
// @Tags 租户管理
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
@@ -562,6 +562,11 @@ func (h *TenantHandler) ResetAPIKey(c *gin.Context) {
|
||||
c.Error(errors.NewInternalServerError("API key service is not configured"))
|
||||
return
|
||||
}
|
||||
if err := h.apiKeyService.RevokeAllAPIKeys(ctx, id); err != nil {
|
||||
logger.ErrorWithFields(ctx, err, map[string]interface{}{"tenant_id": id})
|
||||
c.Error(errors.NewInternalServerError("Failed to reset API key").WithDetails(err.Error()))
|
||||
return
|
||||
}
|
||||
result, err := h.apiKeyService.CreateAPIKey(ctx, interfaces.TenantAPIKeyCreateRequest{
|
||||
TenantID: id,
|
||||
Name: "Tenant API key",
|
||||
|
||||
Reference in New Issue
Block a user