Socket
Socket
Sign inDemoInstall

cidp-node-api-sdk

Package Overview
Dependencies
94
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cidp-node-api-sdk

JWT validator middleware to authorize requests to api resources


Version published
Weekly downloads
1
decreased by-85.71%
Maintainers
1
Install size
9.18 MB
Created
Weekly downloads
 

Readme

Source

CIDP NODE API SDK

A library for application built using node js. Is used to authorize requests to api resources by validating access token.

Features:

  • node library
  • unit tests for the library
  • a demo application using express web framework that consumes the library

Common tasks are present as npm scripts:

  • npm run build to build the library
  • npm run start to run a server with the demo app using express
  • npm run test run unit tests

What's in the CIDP NODE API SDK?

demo/
    ├── app.js
lib/
   ├── index.js
   └── services/
        └── claimService.js
        └── jwtService.js

Files inside lib/ "belong" to library, while demo/ contains demo applications that loads the library.

Libraries do not run by themselves, so it's very useful to have this "demo" apps while developing to see how your library would look like to consumers.

The build step

You can build the library by running npm run build. This will generate a dist/ directory with all the entry points described above.

All the logic for creating the build can be found in ./gulpfile.js. It consists of:

  • Identify any security vulnerabilities
  • Clean dist folder.
  • Transpile with babel.
  • Copy the source to dist folder.

Testing

The CIDP API NODE SDK includes a directory called test containing unit tests to verify it works.

To run the unit tests, do npm run test

Using in the node application

Install node package in your app : npm install cidp-node-api-sdk --save

Import the module in your app. Set the authSettings properties to match the server configuration.



var cidp = require('cidp-node-api-sdk');

var app = express();

//Settings defines
//1.authorityURI - a CIDP instance uri, used by sdk to check if token issuer is a trusted one
//2.The received token should have the required audiece in order to be authorized
var settings = {
  authorityUri: "IdentityServerUri",
  audience: "audience"
};

// use validateJwt middleware to:
//1.Retrieve from authorityUri trusted issuer host names
//2.Check if token issuer host name is trusted
//3.Connect to issuer that generate the received access token
//4.Get metadata about token signing key.
//5.Validate token is not expired and is valid for the audience specified
app.use(cidp.validateJwt(settings));

//use hasClaim middleware to check token contains the claim 
//hasClaim(claimKey,claimValue)
//claimValue should be an array of strings.It allows to give access to profile resource if user role is Admin or Dev
app.get('/profile', cidp.hasClaim('role', ['Admin','Dev']), function (req, res) {
  const user = req.user;
  return res.json(user);
});

//or we can grant access to profile resource if token has profile scope
app.get('/profile', cidp.hasClaim('scope', ['profile']), function (req, res) {
  const user = req.user;
  return res.json(user);
});

Keywords

FAQs

Last updated on 16 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc