Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect.basicAuth is missing - please provide working example for basic authentication #38

Closed
godmar opened this issue Sep 9, 2016 · 0 comments

Comments

@godmar
Copy link

godmar commented Sep 9, 2016

connect no longer has a basicAuth method, because I believe they moved all middleware outside.

This mean that the example is broken.

Could it be fixed?

I'm asking because it took me a long time to figure out how to fix it, I ended up with the following middleware to support basic authentication via LDAP:

const basicAuth = require('basic-auth');
const basicAuthenticator = (req, res, next) => {
    function reject() {
        res.statusCode = 401
        res.setHeader('WWW-Authenticate', 'Basic realm="please use your SLO"')
        res.end('Access denied')
    }

    var credentials = basicAuth(req)
    if (!credentials) return reject();

    ldap.authenticate(credentials.name, credentials.pass, function (err, user) {
        if (err) return reject();
        req.user = credentials.name;
        next();
    });
}

which I am not certain of, quite frankly, whether it handles all errors correctly.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant