Fix auth using header

This commit is contained in:
Michael Jackson
2018-09-01 09:36:48 -07:00
parent 41c3b1fa5f
commit e04db2c49c
11 changed files with 435 additions and 349 deletions

View File

@ -1,9 +1,11 @@
const basicAuth = require("basic-auth");
const AuthAPI = require("../AuthAPI");
const ReadMethods = { GET: true, HEAD: true };
function decodeBase64(string) {
return Buffer.from(string, "base64").toString();
}
/**
* Sets req.user from the payload in the auth token in the request.
*/
@ -12,9 +14,9 @@ function userToken(req, res, next) {
return next();
}
const credentials = basicAuth(req);
const token = credentials
? credentials.pass
const auth = req.get("Authorization");
const token = auth
? decodeBase64(auth)
: (ReadMethods[req.method] ? req.query : req.body).token;
if (!token) {