صفحة توثيق تفصيلية جاهزة للدمج داخل مشروع Yii2 (Advanced/Basic). تحتوي على شرح، إعدادات، وقوالب كود لميزات:
الحزمة تتضمن موديولات ومكونات جاهزة للنسخ داخل مشروعك:
common/modules/ssocommon/modules/otpcommon/modules/biometriccommon/components/SmsComponent.php و common/components/WhatsappComponent.phpconfig_examples/ وملف SQL لـ WebAuthncommon/modules/, common/components/.composer require yiisoft/yii2-authclient
composer require web-auth/webauthn-framework
composer require twilio/sdk
composer require guzzlehttp/guzzle
أضف إلى config/main.php أو frontend/config/main.php:
'modules' => [
'sso' => ['class' => 'common\modules\sso\Module'],
'otp' => ['class' => 'common\modules\otp\Module'],
'biometric' => ['class' => 'common\modules\biometric\Module'],
],
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'YOUR_GOOGLE_CLIENT_ID',
'clientSecret' => 'YOUR_GOOGLE_CLIENT_SECRET',
],
'microsoft' => [
'class' => 'yii\authclient\clients\Azure',
'clientId' => 'YOUR_AZURE_CLIENT_ID',
'clientSecret' => 'YOUR_AZURE_CLIENT_SECRET',
],
],
],
'sms' => [ 'class' => 'common\\components\\SmsComponent', 'apiKey' => 'YOUR_SMS_API_KEY' ],
'whatsapp' => [ 'class' => 'common\\components\\WhatsappComponent', 'accessToken' => 'YOUR_WHATSAPP_ACCESS_TOKEN', 'phoneNumberId' => 'YOUR_PHONE_NUMBER_ID' ],
],
نفّذ ملف SQL لإنشاء جدول اعتماد WebAuthn:
CREATE TABLE `webauthn_credentials` (
`id` int NOT NULL AUTO_INCREMENT,
`user_id` int NOT NULL,
`credential` longtext NOT NULL,
`created_at` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
تأكد أن نموذج User يحتوي الحقول التالية: id, username, email, phone, password_hash, auth_key، وأضف الوظائف:
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
صفحة التسجيل تعرض أزرار OAuth من yii\authclient. بعد المصادقة يرسل الموفر بيانات المستخدم (email, name) ويُنشئ حسابًا إذا لم يكن موجودًا.
تدفق العملية:
SmsComponent أو WhatsappComponent.الاتجاه الصحيح للتطبيقات الحديثة: WebAuthn / Passkeys. المتصفح/الجهاز يولّد مفتاحًا خاصًا ويخزن العام على الخادم. يتطلب HTTPS.
config/main.php أو هيكل User.