Initial V2 commit 4

This commit is contained in:
Hamza-Ayed
2026-04-22 23:16:23 +03:00
parent 3269a836a2
commit 3f4afd0f5c
47 changed files with 456 additions and 72 deletions

View File

@@ -6,8 +6,15 @@ use Closure;
use Illuminate\Http\Request;
/**
* Admin Role Middleware
* Ensures the authenticated user has admin privileges
* وسيط التحقق من صلاحيات المدير (Admin Role Middleware)
*
* الغرض من الملف:
* حماية المسارات (Routes) التي لا يسمح بالدخول إليها إلا للمدراء فقط.
*
* كيفية العمل:
* 1. يفحص نوع المستخدم المخزن في رمز الـ JWT.
* 2. إذا كان نوع المستخدم ليس "admin"، يرفض الطلب ويرجع خطأ (403 Unauthorized).
* 3. إذا كان مديراً، يسمح للطلب بالمرور للمتحكم (Controller) المعني.
*/
class AdminMiddleware
{

View File

@@ -8,16 +8,16 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
/**
* HMAC Signature Validation Middleware
* وسيط التحقق من التوقيع الرقمي (HMAC Validation Middleware)
*
* Validates every API request using HMAC-SHA256 signatures.
* Prevents: Replay attacks, Man-in-the-Middle, Tampering.
* الغرض من الملف:
* توفير طبقة أمان إضافية لجميع الطلبات لضمان عدم التلاعب بالبيانات أثناء انتقالها بين التطبيق والخادم.
*
* Required Headers:
* X-API-Key: unique per user (stored in DB)
* X-Timestamp: Unix timestamp (must be within TOLERANCE window)
* X-Signature: HMAC-SHA256(timestamp|api_key|request_body, api_secret)
* X-Nonce: unique per request (prevents replay attacks)
* كيفية العمل:
* 1. يتطلب وجود "توقيع" (Signature) في رأس الطلب (Headers).
* 2. يقوم الخادم بإعادة حساب التوقيع باستخدام مفتاح سري (API Secret) ومقارنته بالتوقيع المرسل.
* 3. يحمي من هجمات "إعادة الإرسال" (Replay Attacks) عن طريق التحقق من الـ Nonce والـ Timestamp.
* 4. يضمن أن البيانات لم تتغير في الطريق (Data Integrity).
*/
class HmacAuthMiddleware
{

View File

@@ -9,10 +9,16 @@ use Firebase\JWT\Key;
use Firebase\JWT\ExpiredException;
/**
* JWT Authentication Middleware
* وسيط التحقق من الهوية (JWT Authentication Middleware)
*
* Validates JWT tokens from the Authorization header.
* Works in conjunction with HMAC middleware for double-layer security.
* الغرض من الملف:
* التحقق من "رمز الوصول" (Access Token) الذي يحمله المستخدم بعد تسجيل الدخول للتأكد من هويته.
*
* كيفية العمل:
* 1. يستخرج الرمز من رأس الطلب (Authorization Header).
* 2. يقوم بفك تشفير الرمز (Decode) باستخدام مفتاح سري (JWT Secret).
* 3. يستخرج بيانات المستخدم (مثل المعرف والنوع) ويضيفها للطلب ليسهل الوصول إليها في المتحكمات.
* 4. يمنع الطلب إذا كان الرمز منتهي الصلاحية أو غير صحيح.
*/
class JwtAuthMiddleware
{