Skip to content

Commit

Permalink
Provide headers on mgmt token fetch (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpatrick authored Oct 21, 2020
1 parent cf2a1e5 commit b9d286b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/management/ManagementTokenProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var DEFAULT_OPTIONS = { enableCache: true };
* @param {String} options.audience Audience of the Management API.
* @param {Boolean} [options.enableCache=true] Enabled or Disable Cache
* @param {Number} [options.cacheTTLInSeconds] By default the `expires_in` value will be used to determine the cached time of the token, this can be overridden.
* @param {Object} [options.headers] Additional headers that will be added to the outgoing requests.
*
*/
var ManagementTokenProvider = function(options) {
if (!options || typeof options !== 'object') {
Expand Down Expand Up @@ -67,7 +69,8 @@ var ManagementTokenProvider = function(options) {
clientId: this.options.clientId,
clientSecret: this.options.clientSecret,
telemetry: this.options.telemetry,
clientInfo: this.options.clientInfo
clientInfo: this.options.clientInfo,
headers: this.options.headers
};
this.authenticationClient = new AuthenticationClient(authenticationClientOptions);

Expand Down
10 changes: 10 additions & 0 deletions test/management/management-token-provider.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ describe('ManagementTokenProvider', function() {
expect(provider.options.cacheTTLInSeconds).to.be.equal(15);
});

it('should set headers when passed into options', function() {
var config = Object.assign({}, defaultConfig);
config.headers = {
'User-agent': 'node.js',
'Content-Type': 'application/json'
};
var provider = new ManagementTokenProvider(config);
expect(provider.options.headers).to.be.equal(config.headers);
});

it('should handle network errors correctly', function(done) {
var config = Object.assign({}, defaultConfig);
config.domain = 'domain';
Expand Down

0 comments on commit b9d286b

Please sign in to comment.