Loading...
Loading...
Secure PubNub applications with Access Manager, encryption, and TLS
npx skill4agent add pubnub/skills pubnub-securitygrantToken()pubnub.setToken()| Reference | Purpose |
|---|---|
| access-manager.md | PAM setup, token grants, permissions |
| encryption.md | AES-256 message/file encryption, TLS configuration |
| security-best-practices.md | Key security, auth patterns, compliance |
// Server-side only (requires Secret Key)
const token = await pubnub.grantToken({
ttl: 60, // minutes
authorizedUUID: 'user-123',
resources: {
channels: {
'private-room': { read: true, write: true }
}
}
});
// Return token to the clientconst pubnub = new PubNub({
subscribeKey: 'sub-c-...',
publishKey: 'pub-c-...',
userId: 'user-123'
});
// Set the token received from your server
pubnub.setToken(token);// Older PAM approach using grant() and authKey
const pubnub = new PubNub({
subscribeKey: 'sub-c-...',
publishKey: 'pub-c-...',
userId: 'user-123',
authKey: 'auth-token-from-server'
});const pubnub = new PubNub({
subscribeKey: 'sub-c-...',
publishKey: 'pub-c-...',
userId: 'user-123',
cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({
cipherKey: 'my-secret-cipher-key'
})
});grantToken()setToken()authKeygrant()