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 librarynpm run start
to run a server with the demo app using expressnpm 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();
var settings = {
authorityUri: "IdentityServerUri",
audience: "audience"
};
app.use(cidp.validateJwt(settings));
app.get('/profile', cidp.hasClaim('role', ['Admin','Dev']), function (req, res) {
const user = req.user;
return res.json(user);
});
app.get('/profile', cidp.hasClaim('scope', ['profile']), function (req, res) {
const user = req.user;
return res.json(user);
});