1.1.5 • Published 8 years ago

kdp v1.1.5

Weekly downloads
31
License
ISC
Repository
github
Last release
8 years ago

KDP Node SDK

This Node SDK allows you to use KDP as an authentication mechanism for your application or API.

Pre requisites

You'll need a few things to get started, firstly you'll have to create a new app on the KDP dev site, go to the URL below and create your app..

http://dev.researchplatform.tnsglobal.com/#/RegisterApp

Make sure you add the following for Url and Redirect URL, then you will be taken to your App Management page.

URL: http://localhost:8080/ Redirect URL: http://localhost:8080/TokenHandler

And go!

Initialise a new Node project, follow the onscreen instructions.

npm init

Install the kdp package and the express package

npm install kdp --save
npm install express --save

Then create an index.js file and code add the following code, remember to replace the APP ID and APP SECRET from your App Management pages on the KDP site.

// require the needed express and kdp modules
var express = require('express');
var kdpMod = require('kdp');

// set up your KDP config, you can grab these details from app management on the KDP site.
var kdpConfig = {
    https: false,
    url: "dev.researchplatform.tnsglobal.com",
    app_id: "---INSERT YOUR APP ID HERE---",
    app_secret: "---INSERT YOUR APP SECRET HERE---",
    app_name: "My Node app"
}

// create a new instance of the KDP module helpers
var kdp = kdpMod(kdpConfig);

// set up your express app
app = express();

// bind KDP in to the app, this will do all of the redirection and authentication require
// it basically creates the cookies we need to identify a user
kdp.init(app);

// Ok, lets set up an endpoint, this will just be route on your express app with some KDP code inside
//
//   Requirements:
//      The user must be authenticated
//      The user must have BasicAccess permission
//
app.get('/', function (req, res) {

    // use KDP to authorize and check permission
    kdp.authorize(req, res, "BasicAccess", function(user){

        // log the fact the user has logged in to KDP
        kdp.log(user.first_name + ' ' + user.last_name + ' just logged in', user.user_id);

        // send the response and say 'Hello' to your user
        res.send('Hello ' + user.first_name + ' ' + user.last_name + '!');
    });
});

// finally start up the server
app.listen(8080, function () {
    console.log('Example KDP app listening on port 8080!');
});

Finally, try out the magic!

node index.js

What next?

Try the Node.js KDP API Template here...

https://github.com/TNSGlobal/kdp-node-api-template

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.18-b

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago