WebSocket Authentication

Guide how to authenticate your API user to the Niza WebSocket.

To listen to private channels an authorization token is required. This is accomplished by making an HTTP request to the Channel Authorization Endpoint. The authorization token received should be set in the payload of the subscribe message.

Pusher Channel Authorization

If you are using Pusher client the authorization endpoint should be set when initializing Pusher instance, read more about setting the authorization endpoint here.

Example of initialization of the Pusher with channelAuthorization

var pusher = new Pusher("APP_KEY", {
      cluster: "eu",
      forceTLS: true,
      disableStats: true,
      enabledTransports: ["wss", "ws"],
      activityTimeout: 10000,
      channelAuthorization: {
        endpoint: `https://app.niza.io/trade/v1/broadcasting/auth`,
        transport: "ajax",
        headers: {
          "X-API-Key": "[API_KEY]",
          "X-API-Sign": "[GENERATED_SIGNATURE]",
          "Access-Control-Allow-Origin": "*",
        },
      },
    });

Channel Authorization Endpoint

POST /broadcasting/auth

Authorize channel subscription. Request should be made to the general Request URL.

Headers

Name
Value

Content-Type

application/json

X-API-Key

API Key

X-API-Sign

The generated signature, check api authentication.

Body

Name
Type
Description

socket_id

number

The id of the currently connected WebSocket.

channel_name

string

The private channel name you want to subscribe.

Response

{
    "auth": "23d6f445cd259b91adf9:c35ecc2c7a8280911ff4b4818be21ee80ae9b3843f8db60d422a3f5824474ac4"
}

Last updated