authorify-websocket

1.0.0 • Public • Published

Authorify Websocket

A plugin for Authorify that enable websockets. A provided router allow to use both http and websockets like a REST server. When the plugin is loaded it is available under the main namespace of the host application: app.plugin['your short plugin name'].

Prerequisites

This plugin must be installed both in server and client, respectively in conjunction with Authorify and Authorify-Client.

Installation

Install authorify-websocket as usual:

$ npm install --save authorify-websocket

Usage

Server

var restify = require('restify');
var authorify = require('authorify')({
  //... options
});
// create the http server
var server = restify.createServer();
// add plugin to the server
authorify.load('authorify-websocket', 'ws', {
  transports: ['ws', 'http'],
  requestTimeout: 200
});
// get the loaded plugin
var ws = authorify.plugin.ws;
// create the websocket server
ws.createServer(server);
var router = ws.router;
// add routes
router.get('/handshake', ok);
router.get('/auth', ok);
router.get('/logout', ok);
router.post('/test', ok);
// start the server
server.listen(3000);

Client (Node)

// create the client
var client = require('authorify-client')({
  //... options
});
// add plugin to the client
client.load('authorify-websocket', 'ws', {
  transports: ['ws', 'http'],
  requestTimeout: 200
});

Client (browser)

To create a single file to use in browser environment use a simple script that uses browserify:

$ ./build.sh

and add the obtained authorify-websocket.js file to your html file.

NOTE: this file must be added AFTER authorify.js (the client) and BEFORE your script (index.js in this example):

// index.js
var client = authorify;   // authorify is a global exposed by authorify-client
// configure the client
client.setConfig({
  //... options
});
// load plugin
client.load('authorify-websocket', 'ws', {
  transports: ['ws', 'http'],
  requestTimeout: 200
});
// request a resource
var message = { field1: 'value1', field2: 'value2' };
client.post('/test')
  .send(message)
   .end(function(err, res) {
      // the reply here or err only if request is over timeout
  });
// index.html
<html>
  <body>
    <script src="authorify.js"></script>    // this is the browser version of Authorify-Client
    <script src="authorify-websocket.js"></script> 
    <script src="index.js"></script> 
  </body>
</html>

Run Tests

Au usual we use mocha as test framework and you can run all tests simply typing:

$ npm test

A full test for both server and client side is available into authorify package.

For more information about the client please read authorify-client documentation and the local documentation into doc` folder.

Documentation

To create your own documentation you must install JSDuck and type in your terminal:

$ cd /path-of-package
$ ./gen_doc.sh

See full documentation into doc folder.

Convention

The version number is laid out as: major.minor.patch and tries to follow semver as closely as possible but this is how we use our version numbering:

major

A major and possible breaking change has been made in the authorify core. These changes could be not backwards compatible with older versions.

minor

New features are added or a big change has happened with one of the third party libraries.

patch

A bug has been fixed, without any major internal and breaking changes.

Contributing

To contribute to the project follow the GitHub guidelines.

License

This program is released under a GNU Affero General Public License version 3 or above, which in summary means:

  • You can use this program for no cost.
  • You can use this program for both personal and commercial reasons.
  • You do not have to share your own program's code which uses this program.
  • You have to share modifications (e.g bug-fixes) you've made to this program.

For more convoluted language, see the LICENSE file.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    5
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    5

Package Sidebar

Install

npm i authorify-websocket

Weekly Downloads

5

Version

1.0.0

License

AGPL3

Last publish

Collaborators

  • mgesmundo