GithubHelp home page GithubHelp logo

isabella232 / am-chat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pubnub/am-chat

0.0 0.0 0.0 456 KB

A demo of using PubNub Access Manager to secure a public chatting experience.

Home Page: http://pubnub.github.io/am-chat/

JavaScript 95.82% CoffeeScript 1.89% CSS 2.29%

am-chat's Introduction

PubNub Access Manager

PubNub Access Manager (PAM) extends PubNub’s existing security framework by providing a mechanism for application developers to create and enforce secure channels throughout the PubNub Real Time Network. PAM provides the ability to enforce security at three different levels and in any combination of the three: Application (TOP), Channel (Stream), Individual User by User.

Where do I Start?

Getting started guide for PubNub Access Manager: The tutorial links below provides you with a walk-through of the API and how it works including sample code for JavaScript SDK. Here are a list of resources for you to get started:

Because the PubNub Access Manager is super simple, you'll want to see how it works by reading the code:

PubNub Admin Mode with SECRET_KEY

Create an instance of PubNub with Admin Granting Capabilities by including the secret_key.

var pubnub = PUBNUB.init({
    subscribe_key : 'my_subkey',
    publish_key   : 'my_pubkey',
    secret_key    : 'my_secretkey'
});

CoffeeScript Sample App Line Number: https://github.com/pubnub/am-chat/blob/b83f9f198c6bcfe8f812422e66c6cf36839a8c5d/server/index.coffee#L7

Grant User Level Permission with Auth Key

Grant access to an auth_key which can be passed to a single user or group of users.

pubnub.grant({
    channel  : 'privateChat',
    auth_key : 'abxyz12-auth-key-987tuv',
    read     : true,
    write    : true,
    ttl      : 60 // Minutes
});

CoffeeScript Sample App Line Number: https://github.com/pubnub/am-chat/blob/b83f9f198c6bcfe8f812422e66c6cf36839a8c5d/server/index.coffee#L16

NOTE: The auth_key can be anything and we recommend you make it long and unpredictable. Something like: aXMgZm9ybS4NClR5cGUgKG9yIGNvcHk

PubNub User Mode without SECRET_KEY

This is the User Mode. You'll specify the auth_key but never provide the secret_key unless you want to give admin access.

var pubnub = PUBNUB.init({
    subscribe_key : 'my_subkey',
    publish_key   : 'my_pubkey',
    auth_key      : 'my_authkey'  // Generated by Admin
});

CoffeeScript Sample App Line Number: https://github.com/pubnub/am-chat/blob/b83f9f198c6bcfe8f812422e66c6cf36839a8c5d/app/scripts/main.coffee#L10

Grant Channel Level Permission

You simply exclude the auth_key paramater and this will globally grant access to all users.

pubnub.grant({
    channel  : 'privateChat',
    read     : true,
    write    : true,
    ttl      : 60 // Minutes
});

NOTE: You can grant access FOREVER by setting the ttl param to 0.

Revoke User Level Permission with Auth Key

Revoke access to an auth_key.

pubnub.revoke({
    channel  : 'privateChat',
    auth_key : 'abxyz12-auth-key-987tuv'
});

Revoke Channel Level Permission

You simply exclude the auth_key paramater and this will globally revoke access to all users.

pubnub.grant({
    channel : 'privateChat'
});

Secure Your Real-Time Apps

The fundamental operations related to Access Manager are granting and revoking access to keys and channels. In our chat example we will want to control who can join the chat room (subscribe) as well as be able to contribute to the chat (publish).

What is PubNub?

Today’s users expect to interact in real-time. PubNub makes it easy for you to add real-time capabilities to your apps, without worrying about the infrastructure. Build apps that allow your users to engage in real-time across mobile, browser, desktop and server.

What Can I Build With PubNub?

The PubNub Real-Time Network takes care of the connections, global infrastructure and key building blocks for real-time interactivity, so you can focus creating killer apps…

  • Real-Time Collaboration
  • Machine-to-Machine
  • Real-Time Financial Streams
  • Real-Time Location Tracking
  • Call Triggering
  • 2nd Screen Sync
  • Live Dashboards
  • Multi-Player Games
  • Group Chat Rooms
  • Thousands more…

am-chat's People

Contributors

dristic avatar stephenlb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.