-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticateUser.js
More file actions
31 lines (30 loc) · 923 Bytes
/
authenticateUser.js
File metadata and controls
31 lines (30 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const {StatusCodes, ReasonPhrases} = require('http-status-codes');
const ROOT = require(__dirname + '/../config').ROOT;
const authenticateClientId = require(ROOT +
'/utility/oauth/authenticateClientId');
/**
*
* @param {RequestObject} req
* @param {ResponseObject} res
* @param {Object} next
* @return {Promise}
*/
function authenticateUser(req, res, next) {
let clientId = req.get('Authorization');
clientId = clientId.split(' ')[1];
// let clientId = req.body['tokenId'];
return authenticateClientId(clientId)
.then((payload) => {
req.user = {};
req.user.name = payload['name'];
req.user.email = payload['email'];
req.user.picture = payload['picture'];
next();
})
.catch((err) => {
err.statusCode = StatusCodes.UNAUTHORIZED;
err.name = ReasonPhrases.UNAUTHORIZED;
next(err);
});
}
module.exports = authenticateUser;