Docs/Channels
Private Channels
Secure channels with HMAC-SHA256 authentication.
Private Channels
Private channels require server-side authentication before a client can subscribe. This ensures only authorized users receive sensitive data. Channel names must start with private-.
In Socketo Cloud, use your application key wherever these examples refer to
APP_KEY.
How It Works
When a client subscribes to a private channel, the Pusher SDK automatically sends an auth request to your authEndpoint. Your server validates the user and returns a signed response.
Auth Flow
- Client calls
pusher.subscribe('private-channel') - SDK sends auth request to your
authEndpointwithsocket_idandchannel_name - Your server validates the user session
- Your server returns
{ auth: "APP_KEY:SIGNATURE" } - SDK completes the subscription
Auth Response
json
{
"auth": "APP_KEY:HMAC_SIGNATURE"
}Generating the Signature
The signature is an HMAC-SHA256 hash of SOCKET_ID:CHANNEL_NAME using your App Secret.
js
import crypto from 'node:crypto'
function generateAuth(socketId, channelName, appKey, appSecret) {
const stringToSign = `${socketId}:${channelName}`
const signature = crypto
.createHmac('sha256', appSecret)
.update(stringToSign)
.digest('hex')
return { auth: `${appKey}:${signature}` }
}See Auth & Signature for the full guide.
Security Notes
- Never expose your App Secret in client-side code
- Always verify the
socket_idbelongs to the authenticated user - Return
403 Forbiddenif the user is not authorized