Skip to content

A simple chat room demo using PubNub JavaScript pub/sub API for both client and server, combined with PubNub Access Manager APIs and OAuth.

Notifications You must be signed in to change notification settings

xirdev/auth-chat-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PubNub Access Manager Chat Demo

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.

What is PubNub Access Manager?

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

Message Verification with ECC

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.

User Database

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.

Running this Demo on Your Machine Locally

If you want to run this demo on your own machine. Make sure that Node.js is installed.

  1. Fork or download this repo
  2. Install dependencies: $ npm install
  3. Set up your app on GitHub Developer applications (for OAuth)
  4. Include your own config.js file and save it at root of your app dir (See below)
  5. Run code: $ node index.js
  6. Open the web client at http://localhost:3000

config.js

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
  }
};

About

A simple chat room demo using PubNub JavaScript pub/sub API for both client and server, combined with PubNub Access Manager APIs and OAuth.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 81.0%
  • CSS 11.0%
  • HTML 8.0%