Allplmpliedl manual JWT check and restored all driver fields68j2
This commit is contained in:
61
app/Http/Controllers/Api/PaymentTokenController.php
Normal file
61
app/Http/Controllers/Api/PaymentTokenController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Firebase\JWT\JWT;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class PaymentTokenController extends Controller
|
||||
{
|
||||
// 1. مسار الراكب
|
||||
public function generatePassengerToken(Request $request)
|
||||
{
|
||||
// تحقق خاص بالراكب (لا يوجد بصمة سيارة مثلاً)
|
||||
return $this->buildToken($request->user()->id, 'android/ios_passenger', $request->input('fingerPrint'));
|
||||
}
|
||||
|
||||
// 2. مسار السائق
|
||||
public function generateDriverToken(Request $request)
|
||||
{
|
||||
// تحقق خاص بالسائق (ضرورة وجود بصمة جهاز قوية)
|
||||
return $this->buildToken($request->user()->id, 'android/ios_driver', $request->input('fingerPrint'));
|
||||
}
|
||||
|
||||
// 3. مسار المدير
|
||||
public function generateAdminToken(Request $request)
|
||||
{
|
||||
// المدراء لديهم صلاحيات أوسع، قد يكون الـ aud مختلفاً
|
||||
return $this->buildToken($request->user()->id, 'web_admin', 'admin_secure_context');
|
||||
}
|
||||
|
||||
// 4. دالة البناء المركزية (Private)
|
||||
private function buildToken($userId, $audience, $fingerprint)
|
||||
{
|
||||
$keyPath = env('PAYMENT_INTERNAL_KEY_PATH');
|
||||
|
||||
if (!File::exists($keyPath)) {
|
||||
return response()->json(['status' => 'error', 'message' => 'Security Key Missing'], 500);
|
||||
}
|
||||
|
||||
$internalSecret = trim(File::get_contents($keyPath));
|
||||
|
||||
$payload = [
|
||||
'iss' => 'Intaleq_V2',
|
||||
'sub' => $userId,
|
||||
'aud' => $audience,
|
||||
'iat' => time(),
|
||||
'exp' => time() + 60,
|
||||
'fingerprint' => $fingerprint
|
||||
];
|
||||
|
||||
$token = JWT::encode($payload, $internalSecret, 'HS256');
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'token' => $token,
|
||||
'hmac' => hash_hmac('sha256', $token, $internalSecret)
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user