مرجع توسعه‌دهندگان

صدور توکن از بک‌اند شما

روش پشتیبانی‌شده برای صدور توکن ورود — و تنها فیلدی که اگر حذف شود، کنترل تک‌نشستی بی‌صدا از کار می‌افتد.

بازگشت به محصولات توسعه‌دهندگان

چرا از بک‌اند؟

کلید محرمانهٔ سرور هرگز نباید در اپ قرار گیرد. هر کلیدی که در 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.
client_ipstringتوصیه‌شدهThe END USER's public IP address, forwarded from your server. We see the address of whoever calls this endpoint — which, once you mint from your backend, is your data centre for every one of your users. That address decides the country we stamp on the participant AND which media node a new room opens on, so leaving it out can seat a Riyadh audience next to your server instead of next to them. Only honoured on a server-authenticated request (never app_key, where the handset's own address is already correct), and a private or malformed value is ignored rather than rejected.
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.

روی سرور شما

کلید محرمانه فقط اینجاست. فیلدهای مشخص‌شده از اپ می‌آیند — سرور به‌تنهایی آن‌ها را نمی‌داند.

mint-token.js
// 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,

    // 🔴 The user's own IP, not your server's. Without it every user of yours
    // is placed and geo-located as if they sat in your data centre.
    client_ip: req.headers["x-forwarded-for"]?.split(",")[0]?.trim() ?? req.ip,

    // 🔴 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,
  }),
});

در اپ شما

اطلاعات دستگاه را به بک‌اند خودتان بفرستید تا منتقل کند. شناسهٔ دستگاه باید پس از راه‌اندازی مجدد ثابت بماند.

request_token.dart
// 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,
});

کدهای رد (۴۰۳)

هر رد یک code دارد. کد را بخوانید — فقط اولی باید پیام «حذف شدید» را نشان دهد.

کدمعناچه کنید
user_bannedThis user is banned from this room.Show them they were removed. This is the ONLY code that should produce that message.
room_type_disabledThe project does not have this room type enabled.A configuration problem, not a user problem. Never show a removal notice.
streaming_disabledThe streaming service is not enabled for this project.Same — configuration, not the user.
appkey_identity_mint_disabledYou 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 / bearer

Your backend, authenticated with your server secret. The recommended path.

app_key

The device, using the publishable app key. The legacy path — being closed.

آماده‌اید با UTD بسازید؟

حساب خود را بسازید، کیف پول اصلی‌تان را شارژ کنید و سرویس‌هایی را که نیاز دارید روشن کنید.