npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

passport-windowsauth-latest

v3.0.2

Published

Passport strategy for Windows Integrated Authentication (NTLM)

Downloads

5

Readme

Windows Authentication strategy for Passport.js.

Install

npm install passport-windowsauth-latest

Introduction

This module authenticate user with a LDAP directory. It works in two modes Integrated Authentication (often refer as NTLM) or Form Authentication.

Integrated Authentication (IIS)

In this mode, this strategy reads an special server variable from IIS (more info about this here) and then generate a profile. You can optionally pass LDAP credentials to fetch the profile from Active Directory.

In your IIS application authentication settings, disable Anonymous and enable Windows Authentication.

Configure iisnode to pass the special variable LOGON_USER from IIS to node

<configuration>
  <system.webServer>
    <!-- ... -->
    <iisnode promoteServerVars="LOGON_USER" />
  </system.webServer>
</configuration>

If you want to use it with LDAP:

var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth-latest');

passport.use(new WindowsStrategy({
  ldap: {
    url:             'ldap://wellscordoba.wellscordobabank.com/DC=wellscordobabank,DC=com',
    base:            'DC=wellscordobabank,DC=com',
    bindDN:          'someAccount',
    bindCredentials: 'andItsPass'
  }
}, function(profile, done){
  User.findOrCreate({ waId: profile.id }, function (err, user) {
    done(err, user);
  });
}));

If you want to use without LDAP:

var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth-latest');

passport.use(function(profile, done){
  User.findOrCreate({ waId: profile.id }, function (err, user) {
    done(err, user);
  });
});

NOTE: in this case profile only has displayName and id, both containing just the logon name.

Then use the strategy in a route as follows:

app.get('/express-passport',
  passport.authenticate('WindowsAuthentication'),
  function (req, res){
    res.json(req.user);
  });

Integrated Authentication with Apache and mod_auth_kerb

You can take advantage of mod_auth_kerb in linux by using apache as a reverse proxy to your node application. The configuration is not a walk in the park but after you have everything configured it just works.

####1-Generate a keytab in windows

ktpass
-princ service/[email protected]
-mapuser [email protected]
-crypto RC4-HMAC-NT
-ptype KRB5_NT_PRINCIPAL
-pass passssswwword
-out FILE.keytab

####2-Check your /etc/krb5.conf

kinit [email protected]

You should be able to login from the linux machine.

####3-Check your keytab is okay

kinit -V -kt FILE.keytab service/[email protected]

####4-Install apache with the modules

The modules you need are mod-auth-kerb, proxy, proxy_http, headers, rewrite.

####5-Configure your apache

<VirtualHost *:8001>
  ServerAdmin webmaster@localhost

  ProxyPassInterpolateEnv On
  ProxyPass / http://localhost:3000/          # this is the node.js app
  ProxyPassReverse / http://localhost:3000/   # this is the node.js app
  RewriteEngine On
  RewriteCond %{LA-U:REMOTE_USER} (.+)
  RewriteRule . - [E=RU:%1]
  RequestHeader set X-Forwarded-User %{RU}e

  <Proxy *>
      Order deny,allow
      Allow from all
  </Proxy>

  <Location />
      AuthName "Kerberos Login"
      AuthType Kerberos
      Krb5Keytab /path/to/your/FILE.keytab    # VERY IMPORTANT
      KrbAuthRealm CONTOSO.COM
      KrbMethodNegotiate on
      KrbSaveCredentials off
      KrbVerifyKDC off
      KrbServiceName SERVICE/server.CONTOSO.COM
      Require valid-user
  </Location>

  ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log

  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

####6-Configure Passport.js

var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth-latest');

passport.use(new WindowsStrategy({
  ldap: {
    url:             'ldap://wellscordoba.wellscordobabank.com/DC=wellscordobabank,DC=com',
    base:            'DC=wellscordobabank,DC=com',
    bindDN:          'someAccount',
    bindCredentials: 'andItsPass'
  },
  getUserNameFromHeader: function (req) {
    //in the above apache config we set the x-forwarded-user header.
    //mod_auth_kerb uses user@domain
    return req.headers['x-forwarded-user'].split('@')[0];
  }
}, function(profile, done){
  User.findOrCreate({ waId: profile.id }, function (err, user) {
    done(err, user);
  });
}));

Non-integrated authentication

You can use this module to authenticate users against a LDAP server without integrated authentication. You will prompt the user for his username and password in a form like this:

<form action="/login" method="post">
    <div>
        <label>Username:</label>
        <input type="text" name="username"/>
    </div>
    <div>
        <label>Password:</label>
        <input type="password" name="password"/>
    </div>
    <div>
        <input type="submit" value="Log In"/>
    </div>
</form>

and then have a route like this:

app.post('/login',
  passport.authenticate('WindowsAuthentication', {
                                  successRedirect: '/',
                                  failureRedirect: '/login',
                                  failureFlash:    true })
);

The same configuration as explained above is required with the integrated option in false:

var passport = require('passport');
var WindowsStrategy = require('passport-windowsauth-latest');

passport.use(new WindowsStrategy({
  ldap: {
    url:             'ldap://wellscordoba.wellscordobabank.com/DC=wellscordobabank,DC=com',
    base:            'DC=wellscordobabank,DC=com',
    bindDN:          'someAccount',
    bindCredentials: 'andItsPass'
  },
  integrated:      false
}, function(profile, done){
  User.findOrCreate({ waId: profile.id }, function (err, user) {
    done(err, user);
  });
}));

Example profile from LDAP

When you use the LDAP integration the profile follows the Passport.js user profile convention and you have also a _json property with all the profile.

Example:

{
  "id": "fe59e96-4d82-431e-816a-5a688e4ab547",
  "displayName": "Jose Romaniello",
  "name": {
    "familyName": "Romaniello",
    "givenName": "Jose"
  },
  "emails": [
    {
      "value": "[email protected]"
    }
  ],
  "_json": {
    "dn": "CN=Jose Romaniello,CN=Users,DC=wellscordobabank,DC=com",
    "controls": [],
    "objectClass": [
      "top",
      "person",
      "organizationalPerson",
      "user"
    ],
    "cn": "Jose Romaniello",
    "sn": "Romaniello",
    "title": "cantante desafinado - programador",
    "physicalDeliveryOfficeName": "Chief Architect",
    "telephoneNumber": "+543519998822",
    "givenName": "Jose",
    "distinguishedName": "CN=Jose Romaniello,CN=Users,DC=wellscordobabank,DC=com",
    "instanceType": "4",
    "whenCreated": "20130220172116.0Z",
    "whenChanged": "20130220183149.0Z",
    "displayName": "Jose Romaniello",
    "uSNCreated": "12717",
    "uSNChanged": "12792",
    "company": "Wells Cordoba Bank",
    "name": "Jose Romaniello",
    "objectGUID": "fe59e96-4d82-431e-816a-5a688e4ab547",
    "userAccountControl": "66048",
    "badPwdCount": "0",
    "codePage": "0",
    "countryCode": "0",
    "badPasswordTime": "0",
    "lastLogoff": "0",
    "lastLogon": "0",
    "pwdLastSet": "130058544776047558",
    "primaryGroupID": "513",
    "objectSid": "\u0001\u0005\u0000\u0000\u0000\u0000\u0000\u0005\u0015\u0000\u0000\u0000��=��\u001d��uQ��O\u0004\u0000\u0000",
    "accountExpires": "9223372036854775807",
    "logonCount": "0",
    "sAMAccountName": "jromaniello",
    "sAMAccountType": "805306368",
    "userPrincipalName": "[email protected]",
    "objectCategory": "CN=Person,CN=Schema,CN=Configuration,DC=wellscordobabank,DC=com",
    "dSCorePropagationData": [
      "20130220172118.0Z",
      "16010101000000.0Z"
    ],
    "lastLogonTimestamp": "130058572786126285",
    "mail": "[email protected]"
  }
}

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.