Last Updated:
September 20, 2021
by
Muskan Purohit
| Version: 7
| 1,540 views
| 0 followers
members are following updates on this item.
This article describes the Igloo Node.js authentication module, herein referred to as igAuth.
Note: This article assumes you are just looking for an Igloo node authentication module. If you need to deploy a Node.js server application for Igloo from scratch, please view this article first.
The Igloo Node.js server uses the following npm modules:
npm module | Usage |
---|---|
superagent | This handles standard XmlHttpRequest type stuff in Node.js, specifically used to authenticate and make API calls. |
prettyjson | This enables meaningful response output to the console, that is easy to read with color highlighted syntax. |
The Igloo Node.js server uses the following custom modules:
Module | Usage |
---|---|
igAuth | This module. It’s required to create an authenticated session external to an Igloo site. |
Click below to download the Igloo authentication module for Node.js (Fig. 3.1):
(Fig 3.1) Igloo Node.js project file.
Include this JS file with your other custom node modules, and simply require it (Fig 3.2):
/**
* @desc Require igAuth.js in your Node.js main executable JS file
*/
var igAuth = require("./igAuth.js");
(Fig 3.2) Requiring the Igloo Node.js authentication module in your project.
To sign-in, simply call igAuth.signIn(); where necessary (Fig. 3.3)
/**
* @desc Call the function to complete the sign-in process
*/
igAuth.signIn();
(Fig 3.3) Sign-in to your Igloo site.
// igAuth.js
/**
* A module that authenticates and creates an active Igloo session
* @module signIn
*/
/** External authentication using the superagent package */
const request = require('superagent');
/** igAuth.signIn() */
exports.signIn = function () {
/** Igloo issued credentials */
let credentials = {
appId: "000df22c-ece6-4484-a00b-4dc2200eca31", // API Key provided by Igloo to the developer
appPass: "a-secure-api-password", // API Password provided by Igloo to the developer
username: "your-user-login@domain.com", // Your Igloo username
password: "password", // Your Igloo password
community: 'mycommunity.igloocommunities.com' // The FQDN of your Igloo community
};
/** superagent request to connect to the Igloo site */
request
.post('https://mycommunity.igloocommunities.com/.api/api.svc/session/create') // Change to the URL of your Igloo community
.set('Accept', 'application/json')
.set('Content-Type', 'application/x-www-form-urlencoded')
.send(`appId=${credentials.appId}&appPass=${credentials.appPass}&username=${credentials.username}&password=${credentials.password}&community=${credentials.community}&apiversion=1`)
.end(function (err, res) {
if (err || !res.ok) {
console.error('Unable to create session', err);
} else {
/** Your custom code here... */
console.info('Here is your igloo session data:', res.body);
console.info('Your iglooauth session key is:', res.body.response.sessionKey);
}
});
};
(Fig 4.1) Contents of igAuth.js