--- title: "Generate Token Pair" url: https://docs.catalyst.zoho.com/en/sdk/java/v1/cloud-scale/data-streams/generate-token-pair/ description: "This page describes the methods to generate WebSocket access tokens for subscribers in your Java application with sample code snippets." last_updated: 2026-07-07T05:22:22Z service: Cloud Scale type: general related_links: - name: "Data Streams" url: /en/cloud-scale/help/data-streams/introduction --- # Generate Token Pair Before a client can subscribe to a [Data Streams](https://docs.catalyst.zoho.com/en/cloud-scale/help/data-streams/introduction/) 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. ### Get Token Pair using User ID This method generates 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. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.datastream.ZCDatastream; import com.zc.component.datastream.beans.ZCTokenResponse; ``` ```java //Create a Data Streams instance ZCDatastream datastream = ZCDatastream.getInstance(); //Define channel ID and user ID String channelId = "CHANNEL_ID"; Long userId = 30772000000631094L; //Generate token pair using user ID ZCTokenResponse tokenResponse = datastream.getTokenPair(channelId, userId); ``` ### Get Token Pair using Connection Name This method generates 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. #### Sample Code Snippet **Package Imports** ```java import com.zc.component.datastream.ZCDatastream; import com.zc.component.datastream.beans.ZCTokenResponse; ``` ```java //Create a Data Streams instance ZCDatastream datastream = ZCDatastream.getInstance(); //Define channel ID and connection name String channelId = "CHANNEL_ID"; String connectionName = "CONNECTION_NAME"; //Generate token pair using connection name ZCTokenResponse tokenResponse = datastream.getTokenPair(channelId, connectionName); ```