dnt-connect

3.0.2 • Public • Published

DNT Connect

Build status NPM downloads NPM version Node version Dependency status

Node.JS library for DNT's single sign on service – DNT Connect. This README explains the technical implemetation of using DNT Connect in your Node application. For detaials on data returned through the API and various response codes see this document. Please contact opensource@turistforneingen.no if you are interested in using DNT Connect for your application in order to get an API key.

Requirements

Require Node.JS version >= 0.10.

Install

npm install dnt-connect --save

Usage

var Connect = require('dnt-connect');

New Client

var client = new Connect('myClientName', 'myBase64EncodedSecretKey');

Imortant! The key should be a base64 representation of your secret key in order for the dnt-connect package to decrypt the response from DNT Connect properly.

Bounce

Bounce is used to check if a user is currently authenticated with DNT Connect. The bounce url will bounce the user automaticly back to the provided redirect_url with user data if the user is authenticated.

var url = client.bounce('http://mysite.com/auth')

Signon

Signon is used to require a user to sign in with their DNT Connect user or register a new user. The user credentials will be sent to the redirect_url when the users is sucessfully authenticated.

var url = client.signon('http://mysite.com/auth')

Middleare

For your convenience we have provided a fully compatible Express.js middeware tha can bounce or do a full signon of your users. A full example can be found in here.

app.get('/connect', connect.middleware('signon'), function getAuth(req, res) {
  if (req.dntConnect.err) {
    res.status(500).json({error: err.message});
  } else {
    res.status(200).json({data: req.dntConnect.data});
  }
});

Decrypt Response

All data sent and recieved to and from DNT Connect is encrypted by 256 bit AES cipher in CBC mode. In order to read recieved data from DNT Connect your application needs to call #decrypt() wich will use your privat DNT Connect API key to decrypt and verify the data.

NB The return from the #decrypt() method is an Array with two elements in it; data and valid. The reason for this is because of Destructing assignments, new in ECMAScript 6.

try {
  var data = client.decrypt({data: queryData, hmac: queryHmac});
  if (data[1] === false) {
    console.log('Validation failed');
  } else {
    console.log('Decrypted data');
    console.log(data[0]);
  }
} catch (e) {
  // Decryption or serialization failed
}

MIT Licensed

Package Sidebar

Install

npm i dnt-connect

Weekly Downloads

20

Version

3.0.2

License

MIT

Last publish

Collaborators

  • turistforeningen