CIDP NODE SDK
A library for application built using node js. Is used to integrate with identity server for authentication and authorization.
Features:
- node library
- integration tests for the library
- a demo application using express web framework that consumes the library
- a demo application using kraken web framework that consumes the library
Common tasks are present as npm scripts:
npm run build
to build the librarynpm run start:express
to run a server with the demo app using expressnpm run start:kraken
to run a server with the demo app using krakennpm run integration
run integration tests
In UI management make sure client exists:
What's in the CIDP NODE SDK?
demo/
└── express
└── kraken
lib/
├── index.ts
└── services/
└── cidpService.js
└── userService.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.
- Deploy to github.
Testing
The CIDP NODE SDK includes a directory called demo\express\e2e
containing end-to-end tests to verify it works.
To run the integration tests, do npm run integration
which does the following:
- Install dependencies.
- Build library.
- Enter the demo\express app's directory.
- Test the app using Protractor testing framework.
Using in the node application
Install node package in your app : npm install cidp-express-sdk --save
Import the module in your app. Set the oidcSettings properties to match the server configuration.
var express = require('express');
var router = express.Router();
var cidp = require('cidp-express-sdk');
var app = express();
var oidcSettings = {
authority_url: "https://demo.identityserver.io",
client_id: "server.code",
client_secret: "secret",
response_type: "code",
scopes: "openid profile email api offline_access",
session_cookie_name:"sessionCookieName"
ui_locales:"fr-FR",
redirect_uri: "/profile",
post_logout_redirect_uri: "/",
error_url: "/error?errMsg=",
clock_tolerance: 30
onSignOutCallback:function(){}
httpOptions:
{
"rejectUnauthorized": false
},
custom_params: [{ key: "firstname", value: "first" },{ key: "lastname", value: "last" }]
};
Use library middlewares to setup session and connect to CIDP(Collinson Identity Provider) server:
app.use(cidp.cidpMiddleware(oidcSettings));
Use library middlewares to handle login, logout requests:
router.post('/login', cidp.isAuthenticated(ui_locales:'fr-FR'}));
router.post('/logout',cidp.signOut());
router.get('/profile',cidp.isAuthenticated({ui_locales:'fr-FR'}), function (req, res, next) {
var identity = req.identity;
}
router.get('/error*', function (req, res, next) {
var message = req.query.errMsg;
res.render('error', {
message: message,
error: {}
});
});
router.get('/changePassword',cidp.changePassword(returnUrl));
router.get('/loginHistory',cidp.loginHistory(returnUrl));
Cidp service also provides a user helper cidp.getUser(req.identity)
with following properties available:
- expired:boolean - check if token not expired
- authenticated:boolean - check if token exist and not expired
- identityClaims:keyvaluepair - get list of claims from identity token
- accessClaims:keyvaluepair - get list of claims from access token