Authentication using my identities
Use this when you already manage your own users and want them in chat as themselves. Your server makes one call to mint a token for a signed-in user; your app hands that token to the SDK, and from then on every widget and component acts as exactly the identity you minted.
What it takes: one server-side mint call, then a setUserToken on the client.
Your backend stays the source of truth — no passwords or user records to sync.
Step 1 · Mint a token (server side)
Section titled “Step 1 · Mint a token (server side)”Call the mint endpoint with the user’s id. The response’s data.token is a
ready-to-use bearer token for that user.
POST /api/v3/{appid}/user/users/{userid}/session — your API key in the
x-api-token header. Body is optional (send {} for defaults; expiresIn sets a
lifetime in seconds).
const res = await fetch( `https://api.sportstalk247.com/api/v3/${APP_ID}/user/users/u-8842/session`, { method: 'POST', headers: { 'x-api-token': API_KEY, // secret — server only 'Content-Type': 'application/json', }, body: JSON.stringify({ displayname: 'Dave', expiresin: 3600 }), },);
const { data } = await res.json();return data.token; // hand this to the browserusing var http = new HttpClient();http.DefaultRequestHeaders.Add("x-api-token", API_KEY); // secret — server only
var body = new StringContent( "{\"displayname\":\"Dave\",\"expiresin\":3600}", Encoding.UTF8, "application/json");
var res = await http.PostAsync( $"https://api.sportstalk247.com/api/v3/{APP_ID}/user/users/u-8842/session", body);
using var doc = JsonDocument.Parse(await res.Content.ReadAsStringAsync());var token = doc.RootElement.GetProperty("data").GetProperty("token").GetString();curl -X POST \ "https://api.sportstalk247.com/api/v3/$APP_ID/user/users/u-8842/session" \ -H "x-api-token: $API_KEY" \ -H "Content-Type: application/json" \ -d '{ "displayname": "Dave", "expiresin": 3600 }'# → response.data.token is the user's bearer tokenStep 2 · Use the token in your app
Section titled “Step 2 · Use the token in your app”Send the minted token to the browser, hand it to the SDK, and join a room. The token is the user’s identity — no secret in the browser.
import { ChatClient } from 'sportstalk-sdk';
// Public app id only. The minted token identifies the user.const client = ChatClient.init({ appId: APP_ID });
// The token your server minted in Step 1.client.setUserToken(mintedToken);
// Tell the SDK who's joining — must match the userid the token was minted for,// or the server rejects the join (an end-user token can only act as itself).client.setUser({ userid: 'u-8842' });
// Join a room — you're in as that user.await client.joinRoomByCustomId('live-event-chat');