npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

websocket-access-service

v0.90.25

Published

A non-traditional access service that leverages websockets to provide user authentication

Downloads

24

Readme

Websocket Access Service


A non-traditional access service that leverages websockets to provide user authentication.

NPM version Build Status Dependency Status

Introduction

The Websocket Access Service uses tokenized gated messaging and shared keys to accept or deny access to resources. It is designed to be used with an existing multi-channel messaging hub like node-messaging-commons but will work with other messaging systems as well.

Installation

Server

	npm install websocket-access-service --save

Client/Browser

The project includes a "browser" folder with enough to create a small authentication page. Once a user enter's their password, it is set then "authenicate" is called. If the backend services are up, then all should work as expected.

Here is a short snippet of the browser code:

<!DOCTYPE html>
<html>
<head>
    <title>test access page</title>
    <script src="browser-messaging-commons.js"></script>
    <script src="hmac-sha256.js"></script>
    <script src="AccessClient.js"></script>
    <script>
        var client;

        var accessClickHandler = function() {
            // set the password as entered by the user
            client.setUserAccessKey( 'fire-fighter3' );

            // start the websocket process
            client.authenticate();
        };

        var startAccessClient = function() {
            // simulate finding a user with an active session
            var opts = {};
            opts.user  = {
                id:'33e2c605f0334ce7a455ec8f6a60e063',
                session:'2a7f543a-5a4e-44db-a150-b653852ed0c0',
                privateChannel:'/44C4UUX'
            };

            // create the access client instance with user object
            client = AccessClient.createInstance( opts );

            // make available for debugging
            window.client = client;
        };
    </script>
</head>

Client Authentication

The AccessClient class does the work of creating the approprate channels and makeing the requests. Here are the steps...

  • prompt for and set the plain text password
  • create consumer access channel
  • create private producer channel
  • wait for access token and send request to listen on private channel
  • broadcast data on private channel
  • wait for response (with timeout)
  • on ready response, send the encoded password (hash)
  • on response, close the private channel
  • on positive response, do action A
  • on negative response, do action B
  • on timeout, exit with error

Server

The project includes a "bin" folder with a run/start/stop and status scripts. The run script is the same as start, but it runs in the forgound. It looks something like this:

	var config = require('./config.json'),
    	AccessService = require('websocket-access-service'),
        service = AccessService.createInstance( config );

    service.start();

If you have a message service running on this port, then this is enough to start the public producer channel to periodically send out access tokens (one per second). To create and start a generic message service, see this commons project.

Configuration

Here is a sample configuration file.

{
    "port":29169,
    "hubName":"/MessageHub",
    "channels":[ "/access" ],
    "algorithm":"sha256",
    "appkey":"b55d91a2-a68f-48a1-8f4b-c4dfc65d60bb"
}

You would want to have a proxy and preferrably HTTPS in front of this but port 29169 works for development.

Sample User List

The project inclues a very basic sample of access users. You would generate and plug in your own keys through some other process.

[
    {
        "id":"33e2c605f0334ce7a455ec8f6a60e063",
        "session":"2a7f543a-5a4e-44db-a150-b653852ed0c0",
        "privateChannel":"/44C4UUX",
        "accessKey":"<key>"
    },
    {
        "id":"c14975621f564f729323f0e5044fb7ee",
        "session":"4b16e31a-0050-4b00-bc1f-acbe855a5dbc",
        "privateChannel":"/55C4xXufg",
        "accessKey":"<key>"
    }
]

Tests

Unit tests include should/specs, jshint and validate-package. Tests can be run from the command line with this:

    make test

    or

    make watch

    or

    grunt mochaTest jshint validate-package