feat: popup quảng cáo, đặt lại mật khẩu bằng token 80 ký tự, 2FA email, vá lỗ hổng bảo mật
- Popup/banner quảng cáo cấu hình từ admin (loại, link, lịch hiển thị) - Đặt lại mật khẩu: token 80 ký tự kèm check digit Luhn thay cho token+email lộ trong URL, chỉ lưu bản băm, một lần dùng, hết hạn 60 phút - Xác thực 2 lớp qua email khi đăng nhập (mã 6 số, ghi nhớ thiết bị 90 ngày) - ApiAuthCheck chặn ngay tài khoản bị khoá dù JWT còn hạn (trước đây dùng được tới hết TTL) - Handler trả 404 thay vì 500 khi ModelNotFoundException không bọc HttpException - Test ClientTamperingTest: xác nhận IDOR/giả mạo dữ liệu từ client đều bị chặn Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
e888a6ed5d
commit
12d5b4951c
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api\Client\Concerns;
|
||||
use App\Http\Requests\Api\Client\ClientAuthRequest;
|
||||
use App\Http\Requests\Api\Client\ClientRegisterRequest;
|
||||
use App\Http\Resources\Api\Client\ClientResource;
|
||||
use App\Services\Api\Client\ClientTwoFactorService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
trait HandlesClientAuthentication
|
||||
@@ -43,10 +44,26 @@ trait HandlesClientAuthentication
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function login(ClientAuthRequest $request)
|
||||
public function login(ClientAuthRequest $request, ClientTwoFactorService $twoFactor)
|
||||
{
|
||||
$result = $this->authService->authenticateClient($request->validated());
|
||||
$client = $this->authService->verifyCredentials($request->safe()->only(['email', 'password']));
|
||||
|
||||
if ($twoFactor->requiresChallenge($client, $request->input('device_token'))) {
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => ['two_factor' => $twoFactor->startLoginChallenge($client)],
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->loginResponse($this->authService->issueTokens($client));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{client: \App\Models\Customer, token: string, refresh_token: string} $result
|
||||
* @param array<string, mixed> $extra
|
||||
*/
|
||||
protected function loginResponse(array $result, array $extra = [])
|
||||
{
|
||||
$client = $result['client'];
|
||||
$this->activityLogger->logAuth('login', 'customer', $client->id, $client->email);
|
||||
|
||||
@@ -57,6 +74,7 @@ trait HandlesClientAuthentication
|
||||
'token' => $result['token'],
|
||||
'refresh_token' => $result['refresh_token'],
|
||||
'expires_in' => config('jwt.ttl', 60) * 60, // seconds
|
||||
...$extra,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user