Skip to content

Commit

Permalink
Merge pull request #146 from YatinArora-NEC/yatin-arora
Browse files Browse the repository at this point in the history
Added "Authorization" header for Keyrock API
  • Loading branch information
apozohue10 committed Sep 22, 2020
2 parents f9d5bbd + 19d71c2 commit 74bc24c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions controllers/api/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const validate_token = function(req, res, next) {

// Function to check if parameters exist in request
function check_validate_token_request(req) {
const tokenvalue = req.headers.authorization ? req.headers.authorization.split('Bearer ')[1] :req.headers['x-auth-token'];
return new Promise(function(resolve, reject) {
switch (true) {
case ['POST', 'PATCH', 'PUT'].includes(req.method) &&
Expand All @@ -63,17 +64,17 @@ function check_validate_token_request(req) {
},
});
break;
case !req.headers['x-auth-token']:
case (!req.headers.authorization && !req.headers['x-auth-token']):
reject({
error: {
message: 'Expecting to find X-Auth-token in requests',
message: 'Expecting to find X-Auth-token/Authorization in requests',
code: 400,
title: 'Bad Request',
},
});
break;
default:
resolve(req.headers['x-auth-token']);
resolve(tokenvalue);
}
});
}
Expand Down Expand Up @@ -234,6 +235,7 @@ function check_requested_tokens(auth_token_info, subj_token_info) {

// Function to check if parameters exist in request
function check_headers_request(req) {
const tokenvalue = req.headers.authorization ? req.headers.authorization.split('Bearer ')[1] :req.headers['x-auth-token'];
return new Promise(function(resolve, reject) {
switch (true) {
case !req.headers['x-subject-token']:
Expand All @@ -245,18 +247,18 @@ function check_headers_request(req) {
},
});
break;
case !req.headers['x-auth-token']:
case (!req.headers.authorization && !req.headers['x-auth-token']):
reject({
error: {
message: 'Expecting to find X-Auth-token in requests',
message: 'Expecting to find X-Auth-token/Authorization in requests',
code: 400,
title: 'Bad Request',
},
});
break;
default:
resolve({
auth: req.headers['x-auth-token'],
auth: tokenvalue,
subject: req.headers['x-subject-token'],
});
}
Expand Down

0 comments on commit 74bc24c

Please sign in to comment.