I'm developing an API in Express JS. I want to use http-auth library and I've been trying to use digest authentication, but I have not been able to use it. Here is my code:
var app = require('express')(),
routes = require('./routes'),
bodyParser = require('body-parser'),
auth = require('http-auth');
app.use(bodyParser.json()); // Soporta json encoded bodies
app.use(bodyParser.urlencoded({ // Soporta encoded bodies
extended: true
}));
var digest = auth.digest({
realm: 'prueba',
file: __dirname + "/usr.pass"
});
app.use(auth.connect(digest));
// Conectamos todas nuestras rutas
app.use('/', routes);
// Levantamos servidor
app.listen(9999, () => {
Console.log('running');
});
My usr.pass
file has this line: jdurini:prueba:88bfcf02e7f554f9e9ea350b699bc6a7
(password is a MD5 representation por '2315').
I'm using POSTMAN to call my endpoints. In this case, I'm trying POST method on localhost:9999
, and everytime I try, It goes to digest.on('fail') event.
In the Authorization tab, I use this data.
What am I doing wrong? This is my first time using Express, so any comment could be helpful.
Edit 1 - August 14th
Authorization header in postman is as follows:Digest username="jdurini", realm="prueba", nonce="", uri="/", response="2c01bce3e1980c575fc82e32f9943617", opaque=""
. This header is autogenerated when I fill Authorization's form with:
- type: Digest Auth
- username: jdurini
- Realm: prueba
- Password: 2315
No other header is used in the request.