Thinkful-Ed / node-jwt-auth

15 stars 118 forks source link

Basic authentication issue (convert to another process?) #3

Open cklanac opened 6 years ago

cklanac commented 6 years ago

@oampo @benjaminEwhite,

The dialog box used by basic authentication pops up when incorrect UN/PW submission.

The issue can be fixed by adding failWithError: true to the middleware as follows

const basicAuth = passport.authenticate('basic', { session: false, failWithError: true  });

This allows us to remove the www-authenticate header before sending the response which suppresses the built-in dialog.

app.use(function (err, req, res, next) {
  res.removeHeader('www-authenticate');
  next(err);
});
cklanac commented 6 years ago

Beyond fixing the issue with the above solution, we can consider changing to another form of authentication.

I considered Digest initially, but quickly found that it would be difficult to implement in our projects. The key issue is that digest hashes the password in the browser (hence the name) and if we override it with JS for SPAs and HTML forms then we need to hash the password in JS. So if we decide to switch, I suggest we change to Local. Below is a list of pros/cons

Basic Auth:

Digest Auth:

Local Auth:

oampo commented 6 years ago

Yep, I'm definitely for switching to Local Auth here. Fixes the issues with jQuery AJAX, and is just a simple (actually even a little simpler) than Basic Auth. The non-standardized thing is annoying, but I'm not going to lose any sleep over it.