EvenID Node.js SDK
This SDK is a NodeJS client library to work with the EvenID API.
Install
npm install evenid-sdk --save
License
MIT. See LICENSE file.
Unit Tests
EvenID uses Mocha for unit testing. As usual, tests may be run by calling npm test
.
Contacts
Report bugs or suggest features using GitHub issue tracker.
Usage
1 / Create a client to obtain a client ID and client secret
To create a client, register on evenid.com and go to the following page: https://www.evenid.com/clients.
Once created, you obtain a client ID and client secret which were required to communicate with the API.
2 / Add a URL to redirect the person registering in or logging in back to
To add a URL, go to your client page (the one created during previous step) and click on the "Redirection uris" category.
Once created, you obtain the links that you will need to display on your website (following the EvenID's Branding Guidelines).
3 / Use the SDK in your redirect URL
var express = ;var EvenID = ; var app = ; // Replace with your redirect URIapp;
That's it. You've just successfuly implemented login, registration, password recovering, email validation and even test accounts, if you have enabled them.
Use cases
What if I want to add persistent login to my website?
-
Store the refresh token (
resp.refresh_token
) in a separate cookie. -
When an unlogged user access your website, check for cookie existence.
-
If the cookie exists, use it :
/* If you don't store users */ evenID; /* END */ /* If you store users */ evenID; /* END */
If the cookie doesn't exist, display links as usual. That's it.
What if I want to validate user's email?
Just call the validateEmail()
method.
evenID;
The user will receive an email containing a link, which will need to be followed to confirm the ownership of the address. Once verified, user will be redirected to your redirect URL, as usual.
What if I want to inspect an access token?
Just call the inspectToken()
method.
evenID;
What if I want to get the notification behind signed request?
Just call the getNotificationFromSignedRequest()
method.
var notification = evenID;
An exception will be triggered in case of signature mismatch.
Returned errors
Returned errors extend the default Error object and add two properties to it:
-
A
httpStatusCode
property, which will contain the HTTP status code, different from 200, returned by the API. -
A
jsonResponse
property, which will contain the parsed JSON object, returned by the API.