0.2.1 • Published 1 year ago

@userdocks/nodejs-server-sdk v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@userdocks/nodejs-server-sdk

npm GitHub Workflow Status Coveralls branch NPM

The Node.js server SDK for userdocks. Verify access and id tokens on your server.

Table of Contents

Install

npm i @userdocks/nodejs-server-sdk

Methods

Documentation of all the functions and methods this SDK exposes.

getUserdocks

This method returns an object (TUserdocks) that exposes the verify method.

Syntax

Returns a new object.

const userdocks = getUserdocks(options);

Parameters

  • options <object>: an object holding two key value pairs
    • app <object>: an object holding three key value pairs
      • publicKey <string | undefined>: the publicKey of the userdocks application, if already cached on the server (optional)
      • readOnlyApiKey <string>: the read only api key of the userdocks application (required)
      • id <string>: the UUID of the userdocks application (required)
    • authServer <object | undefined>: an object holding three key value pairs (optional)
      • id <string | undefined>: the UUID of the authentication server (optional)
      • apiUri <string | undefined>: the api uri of the authetication server (optional)
      • publicKeyPath <string | undefined>: the pathname to the publicKey ressource on the authetication server (optional)

Return Value

  • userdocks <object>: an object holding one key value pair
    • verify <function>: a method that returns a promise that should resolve a boolean

userdocks.verify

Returns a promise that should resolve a new boolean indicating if a token is valid or not.

Syntax

Returns a promise that should resolve a new boolean.

const userdocks = getUserdocks(options);

const payload = await userdocks.verify(token, tokenType);

Parameters:

  • token <string>: the JSON Web Token you want to verify
  • tokenType <"access" | "id">: the type of the token as string

Return Value:

  • payload: a promise that should resolve the payload of the token including a boolean value valid indicating if the provided token is valid or not

Usage

import getUserdocks from '@userdocks/nodejs-server-sdk';

const token = '<a-json-web-token>';

const userdocks = getUserdocks({
  app: {
    readOnlyApiKey: '<a-read-only-api-key-of-an-userdocks-application>',
    id: '<a-uuid-of-an-userdocks-application>',
  },
});

const payload = await userdocks.verify(token, 'access');

Usage for Development

Start the watcher and link the package locally:

npm run watch
npm run link

Link the package in the project where it will be used:

# if you run "npm i" in your project you need to re-run this command
npm link @userdocks/nodejs-server-sdk

To use this module with typescript and with npm link add the follwing to your tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@userdocks/nodejs-server-sdk": [
        "./node_modules/@userdocks/nodejs-server-sdk"
      ]
    }
  }
}
0.2.1

1 year ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago