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:
@@ -62,6 +62,14 @@ func (r *tenantAPIKeyRepository) RevokeAPIKey(ctx context.Context, tenantID uint
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *tenantAPIKeyRepository) RevokeAllAPIKeys(ctx context.Context, tenantID uint64) error {
|
||||
now := time.Now()
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&types.TenantAPIKey{}).
|
||||
Where("tenant_id = ? AND revoked_at IS NULL", tenantID).
|
||||
Update("revoked_at", &now).Error
|
||||
}
|
||||
|
||||
func (r *tenantAPIKeyRepository) UpdateAPIKeyHash(ctx context.Context, id uint64, hash string) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&types.TenantAPIKey{}).
|
||||
|
||||
Reference in New Issue
Block a user