update rm deadcode

This commit is contained in:
baodev0
2026-09-27 11:42:40 +07:00
parent 82a71244ca
commit 3af59bd9c5
129 changed files with 5194 additions and 2698 deletions
+26 -5
View File
@@ -25,6 +25,7 @@ class ClientAuthService
{
// Refresh token lifetime in days
const REFRESH_TOKEN_TTL_DAYS = 30;
const REFRESH_TOKEN_REUSE_GRACE_SECONDS = 30;
const VERIFY_MAX_ATTEMPTS = 5;
@@ -280,9 +281,27 @@ class ClientAuthService
$record = RefreshToken::where('token', $hash)->first();
if (!$record || $record->isExpired()) {
// Xoá token cũ nếu tồn tại nhưng hết hạn
$record?->delete();
if (!$record) {
throw ValidationException::withMessages([
'refresh_token' => ['Refresh token không hợp lệ hoặc đã hết hạn.'],
]);
}
$isConcurrentRefresh = $record->revoked_at !== null
&& $record->revoked_at->gt(now()->subSeconds(self::REFRESH_TOKEN_REUSE_GRACE_SECONDS));
if ($record->revoked_at !== null && !$isConcurrentRefresh) {
// Token đã rotate rồi mà còn bị dùng lại: có thể đã bị đánh cắp,
// thu hồi toàn bộ refresh token của khách này để buộc đăng nhập lại.
RefreshToken::where('customer_id', $record->customer_id)->delete();
throw ValidationException::withMessages([
'refresh_token' => ['Refresh token đã được sử dụng, mọi phiên đã bị thu hồi.'],
]);
}
if ($record->isExpired()) {
$record->delete();
throw ValidationException::withMessages([
'refresh_token' => ['Refresh token không hợp lệ hoặc đã hết hạn.'],
@@ -298,8 +317,10 @@ class ClientAuthService
]);
}
// Rotation: xoá token cũ
$record->delete();
// Rotation: đánh dấu đã dùng thay vì xoá, để phát hiện reuse nếu bị dùng lại
if (!$isConcurrentRefresh) {
RefreshToken::whereKey($record->getKey())->whereNull('revoked_at')->update(['revoked_at' => now()]);
}
// Tạo access token mới
$newAccessToken = JWTAuth::fromUser($customer);