node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »



GoInstant Authentication for Your Node.js Application

Build Status Coverage Status

This is an implementation of JWT tokens consistent with what's specified in the GoInstant Users and Authentication Guide.

This library is not intended as a general-use JWT library; see JWT-php for that. At the time of this writing, GoInstant supports the JWT IETF draft version 8.


npm install --save goinstant-auth


Construct a signer with your goinstant application key. The application key should be in base64url or base64 string format. To get your key, go to your goinstant dashboard and click on your App.

⚠️ Remember, the Secret Key needs to be treated like a password! Never share it with your users!

  var Signer = require('goinstant-auth').Signer;
  var signer = new Signer(yourGoInstantAppKey);

You can then use this signer to create as many tokens as you want. The domain parameter should be replaced with your website's domain. Groups are optional.

    domain: '', // TODO: replace me 
    displayName: user.fullName(),
    groups: [
        id: 'room-' + roomId,
        displayName: 'Room ' + roomId
  }, function(err, token) {
    if (err) {
      // handle it 
    // otherwise, use the token 



Constructs a Signer object from a base64url or base64 secret key string.

Throws an Error if the secretKey could not be parsed.

sign(userData, extraHeaders={}, cb(err, token))

Creates a JWT as a JWS in Compact Serialization format. Can be called multiple times on the same object, saving you from having to load your secret GoInstant application key every time.

userData is an Object with the following required fields, plus any other custom ones you want to include in the JWT.

  • domain - the domain of your website
  • id - the unique, permanent identity of this user on your website
  • displayName - the name to initially display for this user
  • groups - an array of groups, each group requiring:
    • id - the unique ID of this group, which is handy for defining GoInstant ACLs
    • displayName - the name to display for this group

extraHeaders is completely optional. It's used to define any additional JWS header fields that you want to include.

signSync(userData, extraHeaders={})

Synchronous version of sign(), returning the token string. Throws an exception if the token could not be created.

Warning depending on the size of your tokens, this may block the main javascript thread for too long.


The sign() method userData maps to the following JWT claims. The authoritative list of claims used in GoInstant can be found in the Users and Authentication Guide.

  • domain -> iss (standard claim)
  • id -> sub (standard claim)
  • displayName -> dn (GoInstant private claim)
  • groups -> g (GoInstant private claim)
    • id -> id (GoInstant private claim)
    • displayName -> dn (GoInstant private claim)
  • '' -> aud (standard claim) automatically added

For the extraHeaders parameter in sign(), the alg and typ headers will be overridden by this library.


If you'd like to contribute to or modify node-goinstant-auth, here's a quick guide to get you started.

Development Dependencies

  • node.js >= 0.10
    • 0.11.7 and below cannot be used due to bugs in HMAC streams


Download via GitHub and install npm dependencies:

git clone
cd node-goinstant-auth
npm install


Testing is with the mocha framework. Tests are located in the tests/ directory.

npm test  # uses the locally-installed mocha 


  1. npm version patch (increments x in z.y.x, then makes a commit for package.json, tags that commit)
  2. git push --tags origin master
  3. npm publish

Go to and verify it published (can take several minutes)


Email GoInstant Support or stop by #goinstant on freenode.

For responsible disclosures, email GoInstant Security.

To file a bug or propose a patch, please use github directly.


© 2013 GoInstant Inc., a company. All Rights Reserved.

Licensed under the 3-clause BSD license