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 data_streams reference used below is the component instance created earlier. To know more about this instance, please refer to this section.
Get Token Pair using User ID
This method generates a token pair by passing the channel ID and the user ID to the get_token_pair() method. The user ID represents the unique identifier of the application user who is subscribing to the channel.
Parameters Used
| Parameter Name | Data Type | Definition |
|---|---|---|
| channel_id | String | A Mandatory parameter. Holds the unique ID of the channel. |
| user_id | String | A Mandatory parameter. Holds the unique ID of the user subscribing to the channel. |
# Get token pair using user id
token_by_user = data_streams.get_token_pair("CHANNEL_ID", user_id="USER_ID")
Get Token Pair using Connection Name
This method generates a token pair by passing the channel ID and a connection name to the get_token_pair() method. The connection name is a custom identifier for the subscriber connection.
Parameters Used
| Parameter Name | Data Type | Definition |
|---|---|---|
| channel_id | String | A Mandatory parameter. Holds the unique ID of the channel. |
| connection_name | String | A Mandatory parameter. Holds the custom identifier for the subscriber connection. |
# Get token pair using connection name
token_by_connection = data_streams.get_token_pair("CHANNEL_ID", connection_name="CONNECTION_NAME")
Last Updated 2026-08-13 17:11:55 +0530 IST
Yes
No
Send your feedback to us