Skip to content

Instantly share code, notes, and snippets.

@girliemac
Last active October 1, 2015 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save girliemac/2de6b803e0ec00aba448 to your computer and use it in GitHub Desktop.
Save girliemac/2de6b803e0ec00aba448 to your computer and use it in GitHub Desktop.
PubNub Access Manager Getting Started Guide Code samples
<script src="http://cdn.pubnub.com/pubnub-[version number].js"></script>
<script src="https://cdn.pubnub.com/pubnub-crypto.min.js"></script>
var pubnub = require('pubnub').init({
subscribe_key: 'sub-c-f762fb78-...',
publish_key: 'pub-c-156a6d5f-...',
secret_key: 'sec-c-M2U0N...'
});
var pubnub = PUBNUB.init({
subscribe_key: 'sub-c-f762fb78-...',
publish_key: 'pub-c-156a6d5f-...',
auth_key: 'my_auth_key_from_login'
});
var pubnub = PUBNUB.init({
subscribe_key: 'sub-c-f762fb78-...',
publish_key: 'pub-c-156a6d5f-...',
auth_key: 'my_auth_key_from_login'
});
pubnub.auth('my_new_auth_key');
pubnub.grant({
read: true,
write: true,
ttl: 60,
callback: function(m){console.log(m)},
error: function(m){console.error(m)}
});
pubnub.grant({
channel: 'public-room',
read: true,
write: true,
callback: function(m){console.log(m)}
});
pubnub.grant({
channel: 'private-83659357',
auth_key: 'abcxyz123-auth-key',
read: true,
write: true,
ttl: 60,
callback: function(m){console.log(m)}
});
var channel = 'auth-chat';
pubnub.grant({
channel: channel,
auth_key: '9ae4c23e1a8c6654efddf98c2b8ab5fba3f...', // OAuth token
read: true,
write: true,
callback: function(m){console.log(m)}
});
send.addEventListener('click', function(e) {
pubnub.publish({
channel : channel,
message : {text: input.value}
});
}, false);
["PUBLISH ERROR",{"message":"Forbidden","payload":{"channels":["my-chat"]}}]
pubnub.revoke({...});
pubnub.grant({
read: false,
write: false,
...
});
pubnub.revoke({
channel : channel,
auth_key : '9ae4c23e1a8c6654efddf98c2b8ab5fba3f...'
});
pubnub.audit({callback : function(m){console.log(m)});
pubnub.audit ({
channel: channel,
auth_key: '9ae4c23e1a8c6654efddf98c2b8ab5fba3f...',
callback : function(m){console.log(m)}
});
pubnub.audit({
callback: function(m){
console.log(util.inspect(m, false, null));
}
});
{ channels:
{ channel':
{ auths:
{ '94e4cc3e1-user-auth': { r: 1, m: 0, w: 0, ttl: 1440 },
'619f8945a4f-admin-auth': { r: 1, m: 0, w: 1, ttl: 1440 } } },
'my-chat-pnpres':
{ auths: { '619f8945a4f-admin-auth': { r: 1, m: 0, w: 0, ttl: 1440 } } } },
subscribe_key: 'sub-c-981...',
objects: {},
'channel-groups': {},
level: 'subkey' }
pubnub.grant({
channel: channel+'-pnpres',
auth_key: '9ae4c23e1a8c6654efddf98c2b8ab5fba3f...',
read: true,
write: false,
callback: function(m){console.log(m);} ,
error: function(err){console.log(err);}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment