Try the live demo! (You need a GitHub ccount to login to the chat demo!)
This simple demo is written is JavaScript for both client (JavaScript) and server (Node.js) to demonstrate how PubNub Access manager works and how you can implement in your app.
Once a user login, the user is given a auth token from OAuth. In this demo, the token is used as an auth_key
that the "admin" can reference to grant a read/write permission to the user.
PubNub Access Manager extends PubNub's existing security framework by allowing developers to create and enforce secure access to channels throughout the PubNub Real Time Network. What Access Manager does are:
- Syndicate streams by providing authorization to users to read/write messages to one or more channels
- Grant/revoke permissions for your real time streams at the user/device, channel or key level
- Works with Auth tokens from any existing authentication system: Facebook Connect, Twitter, Google, LDAP, or homegrown solutions
Messages are encrypted with Elliptic curve cryptography (ECC) asymmetric algorithm, to avoid some trolls to spoof users.
To learn more about the digital signature, read Chat Security: User Identification with Digital Signature Message Verification on PubNub Blog.
For this demo, each user's public key (for ECC) is stored in PubNub history for its convenience, however in a real-life scenario, you probably want to store the info in your database.
If you want to run this demo on your own machine. Make sure that Node.js is installed.
- Fork or download this repo
- Install dependencies:
$ npm install
- Set up your app on GitHub Developer applications (for OAuth)
- Include your own
config.js
file and save it at root of your app dir (See below) - Run code:
$ node index.js
- Open the web client at http://localhost:3000
Create a file with your own credintials:
module.exports = {
auth: {
github: {
client_id: '614733a4294d....', // Get them from GitHub
client_secret: '486e17d613bd...',
}
},
pubnub: {
secret_key: 'sec-c-M2U0NDI3....', // get it from PubNub Admin portal
auth_key: '...' // any string you want
}
};