• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    C++
  • License
    ISC License
  • Created almost 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Expose Microsoft Windows SSPI to Node for SSO authentication.

Node expose sspi

Expose the Microsoft Windows SSPI (SSP Interface) to Node.js®.

Use cases:

  • NTLM and Kerberos SSO authentication, both server and client inside a private windows organization network, for instance an ERP in a private company.
  • Active Directory access to users for detailed info.

Requirements: Microsoft Windows OS, NodeJS version >=12.16.1. Architecture: x64 or ia32.

Reference

Install

license npm version sponsor

Just do:

npm i node-expose-sspi

Note: There is a prebuilt binary node addon that will be installed.

Usage

SSO Authentication server use case

mkdir myproject
cd myproject
npm init -y
npm i express
npm i node-expose-sspi

Make an express web server by doing the server.js file:

const express = require('express');
const { sso } = require('node-expose-sspi');

const app = express();
app.use(sso.auth());

app.use((req, res, next) => {
  res.json({
    sso: req.sso,
  });
});

app.listen(3000, () => console.log('Server started on port 3000'));
node server.js

Browser on http://localhost:3000

{
  "sso": {
    "method": "NTLM",
    "user": {
      "domain": "JLG",
      "name": "jlouis",
      "displayName": "Jean-Louis P. GUÉNÉGO",
      "groups": [
        "JLG\\Domain Users",
        "\\Everyone",
        // ...
      ],
      "sid": "S-1-5-21-2022955591-1730574677-3210790899-1103",
      "adUser": {
        // adUser filled only if Active Directory is reachable.
        // ...
        "givenName": ["Jean-Louis"],
        "sn": ["GUÉNÉGO"],
        "c": ["FR"],
        "l": ["TORCY"],
        "postalCode": ["77200"],
        "title": ["IT Consultant"],
        "description": ["My microsoft domain account for demonstrating SSO"]
      }
    }
  }
}

Note: To read JSON file on Chrome, you should use the JSON Formatter Chrome Extension.

Command line client:

  • Git Bash: curl --negotiate -u : http://localhost:3000 -b cookie.txt
  • Powershell: Invoke-WebRequest -uri http://localhost:3000 -UseDefaultCredentials

To know more, you can follow the SSO Reference Manual.

SSO Authentication client use case

See the complete example

Account context status

const { sso } = require('node-expose-sspi');

The sso object has following functions to help you:

  • sso.hasAdminPrivileges(): check if user has administrator privileges. A user can be administrator, but when starting a process, it does not have administrator privileges by default. To have them, the process needs to be started as an administrator. See Microsoft documentation about it.
  • sso.isOnDomain(): check if the computer has joined a domain.
  • sso.isActiveDirectoryReachable(): check if the Active Directory domain controller is reachable.

API

Fully detailed API document.

Browsers

Chrome

No conf. It just works.

Firefox

Unlike Chrome, NTLM and Kerberos are not activated by default in Firefox. To make it working, you need to follow these steps:

  1. Navigate to the URL about:config.
  2. Click past the warning of harmful consequences.
  3. Type negotiate-auth into the filter at the top of the page, in order to remove most of the irrelevant settings from the list.
  4. Double-click on network.negotiate-auth.trusted-uris. A dialogue box for editing the value should appear.
  5. Enter the required hostname(s) and/or URL prefix(es) then click OK. For the above example, it is http://localhost:3000

More detailed info here.

Edge

Edge does not require any configuration. But the browser ask the credentials to the user each time it is started.

IE11

IE11 does not require any configuration. Be careful it does not open JSON files in a simple way.

Typescript

This module is ready to be used with both typescript and javascript. No need extra typings.

Typescript example

Authentication protocols

Kerberos

Kerberos is recommanded for production running. For running with Kerberos protocol, both client and server needs to be joined on a Windows Domain.

3 conditions must be met for running Kerberos:

  • The node server, running node-expose-sspi needs to be run as a domain user with service principal name (SPN) declared in Active Directory.
  • The client browser needs to be run on a windows domain account.
  • The website url needs to be declared in a white list of intranet website.

You can find more detail in the Kerberos dedicated documentation.

NTLM

If you are not on a Windows Domain, node-expose-sspi will use the NLTM authentication protocol.

If both the server and the client are on a Windows Domain, NTLM will be used if the Kerberos conditions are not met. See the Kerberos chapter of this README.

The NTLM protocol is less secure than Kerberos and not secure at all if you are not under an HTTPS connection. This is because both login and password hash go on the HTTP request, just encoded in base64...

Another thing bad in NTLM is that browsers sometimes popup a dialog box to ask credentials to the user. Your users don't like that. This is a bad user experience.

Authentication error analysis

If you encounter error, please read this document before submitting an issue.

Production running

Performance

You should avoid to use the Negotiate protocol each time a user access an authenticated resources, because it may take times.

Just use the Negotiate protocol once with sso.auth() on a specific connection url, and then put a session id cookie associated with the req.sso object. Please see this example.

Server behind a reverse proxy

Example: node server behind an IIS proxy

Examples

To run the examples, just clone this project.

git clone https://github.com/jlguenego/node-expose-sspi.git
npm i
cd node-expose-sspi
cd examples
cd <***example-name***>

Look also at the README.md of the example.

Examples :

Development

As a prerequisites, you need node-gyp and a C++ toolchain installed on your environment.

If you did not installed node-gyp and the C++ toolchain, please open a PowerShell command line as an administrator and do :

npm i -g windows-build-tools

To compile the native node module, do the following:

git clone https://github.com/jlguenego/node-expose-sspi.git
cd node-expose-sspi
npm run build
npm run test

There are 2 dev areas :

  • C++ code: run npm run dev to watch the modifications and recompile ASAP.
  • Typescript code: run npm run build:tsw to recompile while watching.

All tests are done with mocha.

The module debug is used for printing some debug info.

Hardware architecture

To both compile ia32 and x64, run the npm run build:arch command.

TODO

Any idea of new features ? Please tell me and raise an issue. 😊

  • write a loopback example
  • write a nestjs example
  • write a medium article
  • Integrate with passport?
  • Test with 10000 users.
  • UTF8 everywhere

Scenario:

  • linux trial.

Thanks

Thanks to all the people who wrotes the npm modules required by this project.

And a very special thanks to the authors of the node-sspi project that helped me writing this one. I considere node-sspi to be the father of node-expose-sspi.

Thanks also to people raising issues to improve the quality of this module.

Sponsoring

This library design aims to be used in production, in private company environment, doing business, using Microsoft Windows.

To help maintaining it, you can sponsor me with github.

Author

Jean-Louis GUENEGO [email protected] (http://jlg-consulting.com/)

You may participate to complete this project. You can improve this doc, or check the code (memory leak, etc.), create new usefull business cases, etc.

Contributors are welcome!

More Repositories

1

react-sso-example

Example of SSO scenario with React and node-expose-sspi module.
TypeScript
20
star
2

jlg-i18n

AngularJS module for i18n, with pluarlization and interpolation, and locale update
JavaScript
13
star
3

angular-markdown-include

Angular module for markdown and syntax highlighting.
JavaScript
12
star
4

mobile-console-log

console.log in devtools from a mobile
JavaScript
11
star
5

lexer

Lexical analyzer.
TypeScript
10
star
6

crudity

A middleware for exposing a crud resource.
TypeScript
9
star
7

example_angular

Some example regarding angular and javascript
JavaScript
8
star
8

asn1-web

Source code of website https://asn1.netlify.app/
TypeScript
7
star
9

asn.1

☺️ ASN1 tool set : message parsing, validating, generating.
TypeScript
7
star
10

ntlm-parser

Understand the content of a NTLM message.
TypeScript
7
star
11

tree

Tree class in Javascript and Typescript.
TypeScript
7
star
12

angular-bonnes-pratiques

Recensement de bonne pratique pour des projets utilisant AngularJS
4
star
13

syntax-analysis

Syntax analysis - parsers.
TypeScript
3
star
14

example_css

training css example
HTML
3
star
15

circle

web components library for reducing boilerplate code
JavaScript
3
star
16

angular-sso-example

Angular app using node-expose-sspi for doing SSO
TypeScript
3
star
17

vscode-algol68

Visual Studio Code extension for ALGOL68
3
star
18

example_node

JavaScript
3
star
19

example_react

React
JavaScript
2
star
20

angular-user

Give some business angular modules for rapid website development : layout, user.
TypeScript
2
star
21

example_angular5

angular 2 4 5 ... example
TypeScript
2
star
22

example_https

setup an https server locally or on google compute engine with letsencrypt.
JavaScript
2
star
23

jlg-bubble

Angular attribute directive that generates nice SVG background with static bubbles.
JavaScript
2
star
24

algol

2
star
25

sudoku-generator

Sudoku generator and carving
TypeScript
2
star
26

cours_angular

site web pour donner le cours d'angular
HTML
2
star
27

esbuild-watch-restart

A nodemon like solution with ES Module and typescript
JavaScript
2
star
28

crudity-demo

demo for crudity
TypeScript
1
star
29

express-oauth2-client

OAuth2 client for express.
TypeScript
1
star
30

exo-ift

JavaScript
1
star
31

vue-sso-example

Vue example for node-expose-sspi
Vue
1
star
32

jlg-backup

TypeScript
1
star
33

example_webcomponents

web components example tutorial
JavaScript
1
star
34

gestion-titres

Gestion Titres
Vue
1
star
35

architect

JavaScript
1
star
36

angular-jlg-datepicker

Angular wrapper on eternicode's bootstrap datepicker
HTML
1
star
37

crudity_example

TypeScript
1
star
38

aspeech

test speech recognition with angular
TypeScript
1
star
39

wordpress-angularjs-theme

wordpress angularjs theme example json rest api
JavaScript
1
star
40

a

command line made easy. Aliasing git, docker, kubectl, etc.
JavaScript
1
star
41

france-dataviz

Map your CSV file to a France map
TypeScript
1
star
42

sudoku-react

sudoku react redux
JavaScript
1
star
43

sudoku

sudoku with Angular and unidirectional flow, and immutable state.
TypeScript
1
star
44

example_boa

woa example
JavaScript
1
star
45

graph

Graph Theory
TypeScript
1
star
46

set

Javascript/Typescript - Operations on Set
TypeScript
1
star
47

visual-cs143

Website for illustrating CS143 stanford course examples about compilers.
TypeScript
1
star
48

angular-tools

🧰 Misc tools for Angular ERP application
TypeScript
1
star
49

moe-calendar

TypeScript
1
star
50

example-fuj

Example for Angular, Node, Express, MongoDB, Docker project.
TypeScript
1
star
51

cigale

CSS Framework
HTML
1
star
52

sparql-bin

Command line sparql utility
JavaScript
1
star
53

angular-jlg-daterangepicker

Angular directive wrapper on Dan Grossman bootstrap-daterangepicker jQuery plugin
HTML
1
star
54

angular-webpack

angular webpack starter
JavaScript
1
star
55

example_gul_unit

Exemples unitaires Angular pour Orsys GUL
JavaScript
1
star
56

mecanique-quantique

1
star
57

mandelbrot

mandelbrot canva html js systemjs
JavaScript
1
star
58

github-stars

See how many Github repositories have more than X stars.
TypeScript
1
star
59

android-jlg-tracker

JLG Tracker
Java
1
star
60

jean-louis-usable-light-syntax

A usable light syntax theme for Atom
CSS
1
star