إنتقل إلى المحتوى الرئيسي

المصادقة (Authentication)

Homatic تستخدم Laravel Sanctum — Bearer tokens للـ API.

Base URLs

APIURL
Tenanthttps://{subdomain}.homatic.io/api/v1
Centralhttps://api.homatic.io/api/central/v1
Portalhttps://api.homatic.io/api

تسجيل دخول Tenant

POST /api/v1/auth/login
Host: acme.homatic.io
Content-Type: application/json

{
"email": "admin@example.com",
"password": "secret"
}

Response 200:

{
"data": {
"user": { "id": 1, "name": "Admin", "email": "admin@example.com" },
"token": "1|abcdef..."
},
"message": "Logged in."
}

تسجيل دخول Central (Super Admin)

POST /api/central/v1/auth/login
Content-Type: application/json

{
"email": "superadmin@homatic.com",
"password": "secret"
}

Portal Login

POST /api/portal/login
Content-Type: application/json

{
"email": "viewer@example.com",
"password": "secret",
"subdomain": "acme"
}

Headers المطلوبة

Authorization: Bearer {token}
Accept: application/json
Content-Type: application/json

للطلبات عبر نطاق مركزي بدون subdomain:

X-Tenant-Subdomain: acme

المستخدم الحالي

GET /api/v1/auth/me
Authorization: Bearer {token}

تسجيل الخروج

POST /api/v1/auth/logout
Authorization: Bearer {token}

مثال cURL

curl -X POST https://acme.homatic.io/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@example.com","password":"secret"}'

curl https://acme.homatic.io/api/v1/devices \
-H "Authorization: Bearer 1|abcdef..." \
-H "Accept: application/json"

أخطاء شائعة

Codeالمعنى
401Token غير صالح أو منتهي
403صلاحية غير كافية (role)
422بيانات validation خاطئة