صكّ التوكن من الباكإند
الطريقة المعتمدة لتوليد توكن الدخول — وحقلٌ واحد لو سقط، تتعطّل الجلسة الواحدة في صمت.
ليه من الباكإند؟
السرّ بتاعك ما ينزلش في التطبيق أبدًا. أي مفتاح يتشحن مع الـAPK ينفع يتفكّ ويُنتحل بيه أي مستخدم.
مرّر حقائق الجهاز
سيرفرك ما بيشوفش الجهاز. التطبيق هو اللي يبعتها لسيرفرك، وسيرفرك يمرّرها لنا في نفس الطلب.
السقوط صامت
من غير device_id، فرض «حساب واحد على جهاز واحد» بيرجع بدري من غير خطأ ولا لوج. التوكن بينجح، والحماية بتبقى مطفية.
ده مقيس، مش متوقَّع
على ثلاث ساعات دخولات حقيقية: التوكنات المصكوكة من الباكإند ٣٬٢٢٤ دخولاً — ١٠٠٪ منها بلا معرّف جهاز. المصكوكة من الكِت على الجهاز ١٬٦٤١ دخولاً — صفر٪. نفس المشروع بيعطي النتيجتين حسب مين صكّ.
حقول طلب التوكن
POST إلى /api/v1/token بسرّ السيرفر في الترويسة.
| الحقل | المستوى | المعنى |
|---|---|---|
user_idstring | مطلوب | Who the token is for. Your own user id. (Previously `identity` — still accepted.) |
room_idstring | مطلوب | Which room they are joining. (Previously `room_name` — still accepted.) |
device_idstring | موصى به | A stable id for the PHYSICAL DEVICE — not the user, and not the session. This is what enforces one account on one device: when the same user_id joins from a different device_id, the previous device is messaged and removed. Omit it and that enforcement silently does nothing: the check returns early, logs nothing, and the old device stays signed in. |
device_modelstring | موصى به | e.g. SM-A175F. Feeds per-handset quality analysis — which models have audio or video trouble. |
osstring | موصى به | android | ios. |
os_versionstring | موصى به | e.g. 14. |
app_versionstring | موصى به | Your app's version, so a regression can be traced to a release. |
display_namestring | اختياري | Shown to other participants. Omit it and the name stays empty — we never substitute the user id for it. |
rolestring | اختياري | Only honoured from a server-signed request, and only while your project still carries the client-asserted-role exception. The supported path is PUT /rooms/:room/participants/:id/role. |
typestring | اختياري | audio_room | live_stream. Legacy kits send `service` (+ `kind`) instead and the type is derived. |
على سيرفرك
السرّ هنا وبس. الحقول المعلّمة بالأحمر جاية من التطبيق — سيرفرك ما يقدرش يعرفها لوحده.
// Your backend — the app never sees the server secret.
const res = await fetch("https://engine.udt-stream.com/api/v1/token", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-App-Secret": process.env.UTD_SERVER_SECRET, // never ship this in the app
},
body: JSON.stringify({
user_id: currentUser.id,
room_id: roomId,
// 🔴 Forwarded FROM THE APP. Your server cannot know these on its own,
// and without device_id one-account-one-device stops working for your users.
device_id: body.device_id,
device_model: body.device_model,
os: body.os,
os_version: body.os_version,
app_version: body.app_version,
}),
});في تطبيقك
ابعت حقائق الجهاز لسيرفرك أنت، وهو يمرّرها. معرّف الجهاز لازم يفضل ثابت بعد إعادة تشغيل التطبيق.
// Your app — send the device facts to YOUR backend, which forwards them to us.
final deviceId = await MyDeviceIdentity.stableId(); // persisted, survives app restarts
await myApi.post("/rooms/$roomId/token", body: {
"device_id": deviceId,
"device_model": deviceInfo.model,
"os": Platform.isAndroid ? "android" : "ios",
"os_version": deviceInfo.version,
"app_version": packageInfo.version,
});أكواد الرفض (403)
كل رفض بيحمل code. اقرأ الكود — ما تعرضش «اتشالت من الغرفة» إلا على الأول منهم.
| الكود | المعنى | اعمل إيه |
|---|---|---|
user_banned | This user is banned from this room. | Show them they were removed. This is the ONLY code that should produce that message. |
room_type_disabled | The project does not have this room type enabled. | A configuration problem, not a user problem. Never show a removal notice. |
streaming_disabled | The streaming service is not enabled for this project. | Same — configuration, not the user. |
appkey_identity_mint_disabled | You tried to mint an identity-bearing token with the publishable app_key. | Mint from your backend with the server secret instead. This is the path this page describes. |
أوضاع المصادقة
المحرّك بيسجّل وضع المصادقة على كل دخول، فتقدر تتأكد أنت على أي مسار فعلاً.
secret / signature / bearerYour backend, authenticated with your server secret. The recommended path.
app_keyThe device, using the publishable app key. The legacy path — being closed.