Node.js Cookie Authentication w/Domino

Mindwatering Incorporated

Author: Tripp W Black

Created: 10/01/2018 at 02:05 PM

 

Category:
Notes Developer Tips
JavaScript

Task:
Reuse Domino login authentication in Node.js.


Technique to Accomplish:
Add a new field to the DomCfg login form used by your Internet Site doc.


Steps:
1. Open the Login form in Designer:
Admin client --> Files tab --> Domino Web Server Configuration / DomCfg.nsf --> Right-click, Open in Designer

In Domino Designer, Under Forms --> Open the correct login form for your server's set-up. (e.g. MWLoginForm or just LoginForm.


2. Add a new field DomAuth.
Type: Text - Computed

Copy and paste in the following code below.
- The text is customized from the <computed text> above the login fields on the form.
- It sets two headers, one called DomAuth for a status number, and the second called DomAuthMsg for allowing Node.JS to get the status message w/o having to recreate it.

sDefault := "Please identify yourself:";
sNotEnough := "%1, you are not authorized to access %2." + @NewLine + @NewLine + "Please sign in with a name which has sufficient access rights:";
sInvalid := "You provided an invalid username or password." + @NewLine + @NewLine + "Please sign in again:";
sExpired := "Your login has expired. Please sign in again:";
sOutOfSync := "%1, your login has been invalidated due to a timing issue with the login servers." + @NewLine + @NewLine + "(The servers may need to have their clocks synchronized to resolve this.)" + @NewLine + @NewLine + "Please sign in again:";

User := @ProperCase(@Name([CN]; @UserName));
URL := @Right(redirectTo; "/");
URL := @If(@Contains(URL; "?"); @Left(URL; "?"); URL);

List := User:URL;
@For(n:=1; n<=@Elements(List); n:=n+1;
sNotEnough := @ReplaceSubstring(sNotEnough; "%" + @Text(n); List[n]);
sOutOfSync := @ReplaceSubstring(sOutOfSync; "%" + @Text(n); List[n])
);

tmp2:= @If( reasonType = "0"; sDefault;
reasonType = "1"; sNotEnough;
reasonType = "2"; sInvalid;
reasonType = "3"; sExpired;
reasonType = "4"; sOutOfSync;
sDefault
);

tmp:= @If(reasonType = ""; "0";
reasonType);

@SetHTTPHeader("DomAuth"; tmp);
@SetHTTPHeader("DomAuthMsg"; tmp2 )


3. Try the login form.
You should receive a Response like:

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Date: Tue, 02 Oct 2018 00:01:51 GMT
X-Frame-Options: SAMEORIGIN
Content-Length: 3953
Expires: Tue, 01 Jan 1980 06:00:00 GMT
Cache-Control: no-cache
DomAuthMsg: You provided an invalid username or password.
DomAuth: 2
Strict-Transport-Security: max-age=0
Server: Lotus-Domino
X-Content-Type-Option: nosniff

4. Update your app to allow Domino Data services in the Application properties.
File --> Application --> Properties --> Beany Hat (Advanced) tab --> Domino Data Service field --> from Never to Views and Documents

5. Create Node.js server JS to test receiving authentication headers:
const express = require("express");
const path = require("path");
const pjson = require("./package.json");
const port = ("port", process.env.PORT || 80);
const app = express();
const rp = require('request-promise');

// proxy domino pages on port 80 at server.mindwatering.com/dom
app.get("/dom", function(req, res, next) {
const domoptions = {
uri: "https://server.mindwatering.com/myapp.nsf/api/data/collections/name/all",
responseWithFullResponse: true
}
}

rp(domoptions).then(function(response) {
const {headers, body} = response;
if('domauth' in headers) {
// failure
return res.status(401).send(headers.domauthmsg);
}
return res.send(response.body);
}

app.use(express.static('public'));
const server = app.listen(port);


5. Start your node server.
Check your app:
https://server.mindwatering.com/dom



previous page