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

sk-simple-token-security

v1.3.0

Published

Simple token based security strategy for SignalK Node Server

Downloads

3

Readme

sk-simple-token-security

Greenkeeper badge

JWT security for SignalK Node Server

Installation

Make sure you have the latest node server and use the App Store to install the signalk-jwt-security-config plugin.

Security

To enabled security on node server, add an authentication section to your settings .json file.

Here is an example:

  "security": {
    "strategy": "sk-simple-token-security",
    "jwtSecretKey": "tyPaYnCtpZLZjNXyLRKnspZHQyLGZUgkYvtwE7quwZDaZmAnqpKntRqDjTciVazV",
  }

For a full example settings file see example-node-server-settings.json

User Types

  • admin - an admin can do anything incuding installing plugins, configuring plugins, restarting the server, etc. Including anything that the readonly and readwrite users can do.
  • readwrite - a readwrite user can use web apps, read from the rest and ws api's, and post to the rest api.
  • readonly - a readlony user can read from the rest, ws and /plugin apis

JWT Usage

When JWT is turned on, all requests require a valid token to be present.

JWT requires a secret key, which is the jwtSecretKey in the example above. This can be any string, but it's recommended to use a good password generator that can generate a long string.

JWT tokens should have an expriation time, this is set using the jwtExpiration setting above. This defaults to 1 hour.

Getting a token

To get a token (which will expire), send a PUT request to /signalk/v1/login. This should contain a json object with username and password.

Example using curl:

curl -v -H 'Content-Type: application/json' -X PUT -d '{ "username": "admin", "password": "password"}' http://localhost:3000/signalk/v1/login

This returns a json object which includes the token:

{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImFkbWluIiwiaWF0IjoxNDk4MTg1MjAwfQ.c5hR66gm_GdE1c8eukUCxNhv-SEApCpMo3JCdUqEDEk"}

Using the JWT token for REST requests

All REST requests should then include the standard Authorization HTTP header with all requests. The value of the header should be JWT a space and then the token.

Example using curl:

curl -v -H 'Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImFkbWluIiwiaWF0IjoxNDk4MTYwMzEwfQ.7xvxLUechuztChRvGaYq_bpjYvu4NMpZe-uZqeAQV5c' http://localhost:3000/signalk/v1/api/vessels/self

Using the JWT token for streaming requests

These requests can use the same method as REST requests above or include the token as a query parameter.

Example using wscat:

wscat -c "ws://localhost:3000/signalk/v1/stream?subscribe=all&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImFkbWluIiwiaWF0IjoxNDk4MTYwMzEwfQ.7xvxLUechuztChRvGaYq_bpjYvu4NMpZe-uZqeAQV5c"