Skip to content

Commit

Permalink
if there is no leave the header empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Klein committed Jun 18, 2019
1 parent 3420aac commit 6e04754
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/rest_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ module.exports.RestClient = function (options) {
public: options.accessToken,
secret: options.accessTokenSecret
};
function buildHeader(request_data, request_token = '') {
if (request_token) {
return { 'Authorization': 'Bearer ' + request_token };
}
if (oauth.consumer.public && oauth.consumer.secret) {
return oauth.toHeader(oauth.authorize(request_data, token))
}

return {};
}

function apiCall(request_data, request_token = '') {
logger.debug('Calling API endpoint: ' + request_data.method + ' ' + request_data.url + ' token: ' + request_token);

logger.info({
url: request_data.url,
method: request_data.method,
headers: request_token ? { 'Authorization': 'Bearer ' + request_token } : oauth.toHeader(oauth.authorize(request_data, token)),
headers: buildHeader(request_token),
json: true,
body: request_data.body,
});
Expand All @@ -35,7 +45,7 @@ module.exports.RestClient = function (options) {
request({
url: request_data.url,
method: request_data.method,
headers: request_token ? { 'Authorization': 'Bearer ' + request_token } : oauth.toHeader(oauth.authorize(request_data, token)),
headers: buildHeader(request_token),
json: true,
body: request_data.body,
}, function (error, response, body) {
Expand Down

0 comments on commit 6e04754

Please sign in to comment.