Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Added OAuth2 authentication support
Browse files Browse the repository at this point in the history
Added OAuth2 authentication support
  • Loading branch information
manivinesh authored and sfdrogojan committed May 20, 2019
1 parent a0df00a commit 77d3434
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/fuel-rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class FuelRest {
const headers = options.headers;

options.uri = helpers.resolveUri(this.origin, options.uri);
if(this.AuthClient.authVersion === 2){
options.uri = helpers.resolveUriForOAuth2(options.uri, tokenInfo.rest_instance_url);
}
options.headers = Object.assign({}, this.defaultHeaders, options.headers, {
// on a retry, the auth header is removed, so this will only add the header passed in
// if it's not the retry
Expand Down
4 changes: 4 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ module.exports = {
uri = url.resolve(origin, uri);
}
return uri;
},
resolveUriForOAuth2(uri, restUrl) {
let urlParts = uri.toLowerCase().split(".com/");
return restUrl + urlParts[1];
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fuel-rest",
"version": "3.1.0",
"version": "3.2.0",
"description": "Node library for performing REST API calls to Salesforce Marketing Cloud (formerly ExactTarget).",
"main": "./lib/fuel-rest.js",
"scripts": {
Expand Down
12 changes: 12 additions & 0 deletions test/specs/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,16 @@ describe('helpers', () => {
expect(resolveSpy.calledOnce).to.be.false;
});
});

describe("resolveUriForOAuth2", () => {
it('should resolve an URI for OAuth2', () => {
let result = helpers.resolveUriForOAuth2('https://www.exacttargetapis.com/hub/v1/campaigns','https://abc.rest.marketingcloudqaapis.com/');
expect(result).to.equal('https://abc.rest.marketingcloudqaapis.com/hub/v1/campaigns');
});

it('should resolve an URI for OAuth2 indifferent of casing', () => {
let result = helpers.resolveUriForOAuth2('https://www.exacttargetapis.COM/hub/v1/campaigns','https://abc.rest.marketingcloudqaapis.com/');
expect(result).to.equal('https://abc.rest.marketingcloudqaapis.com/hub/v1/campaigns');
});
});
});

0 comments on commit 77d3434

Please sign in to comment.