2

The main project my company is working on is an AngularJS web app that calls a C#.Net REST API for all the data. The users of this application are all logged into Windows computers that are tied to an Active Directory. This means that all authentication is handled by the OS, since all credentials are automatically sent by the web browser and handled by IIS.

My newest task is to have a different NodeJS application call the REST service and do some stuff with the data. Unfortunately even when I am logged onto the computer with proper Active Directory credentials, none of it gets sent along with the REST requests, which results in a 401.2 error from IIS. What is the proper way to make sure the already existing Active Directory credentials are sent with the NodeJS REST Request?

1 Answer 1

2

There is node-sspi. Example of usage:

'use strict';

var express = require('express');
var app = express();
var server = require('http').createServer(app);

app.use(function (req, res, next) {
  var nodeSSPI = require('node-sspi');
  var nodeSSPIObj = new nodeSSPI({
    retrieveGroups: true
  });
  nodeSSPIObj.authenticate(req, res, function(err){
    res.finished || next();
  });
});

app.use(function (req, res, next) {
  var out = 'Hello ' + req.connection.user + '! You belong to following groups:<br/><ul>';
  if (req.connection.userGroups) {
    for (var i in req.connection.userGroups) {
      out += '<li>'+ req.connection.userGroups[i] + '</li><br/>\n';
    }
  }
  out += '</ul>';
  res.send(out);
});

// Start server
var port = process.env.PORT || 3000;
server.listen(port, function () {
  console.log('Express server listening on port %d in %s mode', port, app.get('env'));
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.