Generate Token Pair

Before a client can subscribe to a Data Streams channel, it must obtain a token pair to authenticate the WebSocket connection. The token pair can be generated using either a user ID or a connection name.

You can generate the token pair in two ways as described in this section. The datastreams reference used in the code below is the component instance created earlier.

Get Token Pair using Connection Name

You can generate a token pair by passing the channel ID and a connection name to the getTokenPair() method. The connection name is a custom identifier for the subscriber connection. The promise returned here will be resolved to a token pair object.

Parameters Used

Parameter Name Data Type Definition
channelId String A Mandatory parameter. Holds the unique ID of the channel.
connectionName String A Mandatory parameter. Holds the custom identifier for the subscriber connection.
copy
//Generate token pair using connection name
const response = await datastreams.getTokenPair(CRICKET_CHANNEL_ID, {
  connectionName: "cricketScoreUpdates"
});

Get Token Pair using User ID

Alternatively, you can generate a token pair by passing the channel ID and the user ID to the getTokenPair() method. The user ID represents the unique identifier of the application user who is subscribing to the channel. The promise returned here will be resolved to a token pair object.

Parameters Used

Parameter Name Data Type Definition
channelId String A Mandatory parameter. Holds the unique ID of the channel.
userId String A Mandatory parameter. Holds the unique ID of the user subscribing to the channel.
copy
//Generate token pair using user ID
const response = await datastreams.getTokenPair(CRICKET_CHANNEL_ID, {
  userId: "userId"
});

Last Updated 2026-10-05 20:43:57 +0530 IST