Skip to content

Commit dbf65ec

Browse files
authored
Allow httpOptions to be passed to SSO credentials (#4200)
1 parent 6d450b7 commit dbf65ec

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "SSO",
4+
"description": "sso did not allow httpOptions to be passed through"
5+
}

lib/credentials/sso_credentials.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Credentials} from '../credentials';
22
import SSO = require('../../clients/sso');
3+
import { HTTPOptions } from '../config-base';
34
export class SsoCredentials extends Credentials {
45
/**
56
* Creates a new SsoCredentials object.
@@ -8,6 +9,7 @@ export class SsoCredentials extends Credentials {
89
}
910

1011
interface SsoCredentialsOptions {
12+
httpOptions?: HTTPOptions,
1113
profile?: string;
1214
filename?: string;
1315
ssoClient?: SSO;

lib/credentials/sso_credentials.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ AWS.SsoCredentials = AWS.util.inherit(AWS.Credentials, {
6060
this.filename = options.filename;
6161
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
6262
this.service = options.ssoClient;
63+
this.httpOptions = options.httpOptions || null;
6364
this.get(options.callback || AWS.util.fn.noop);
6465
},
6566

@@ -130,7 +131,10 @@ AWS.SsoCredentials = AWS.util.inherit(AWS.Credentials, {
130131
}
131132

132133
if (!self.service || self.service.config.region !== profile.sso_region) {
133-
self.service = new AWS.SSO({ region: profile.sso_region });
134+
self.service = new AWS.SSO({
135+
region: profile.sso_region,
136+
httpOptions: this.httpOptions,
137+
});
134138
}
135139
var request = {
136140
accessToken: cacheContent.accessToken,

test/credentials.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,26 @@ const exp = require('constants');
572572
done();
573573
});
574574
});
575+
it('passes httpOptions through', function(done) {
576+
var httpClient, spy;
577+
helpers.mockHttpResponse(200, {}, '<AssumeRoleResponse xmlns="https://sts.amazonaws.com/doc/2011-06-15/">\n <AssumeRoleResult>\n <Credentials>\n <AccessKeyId>KEY</AccessKeyId>\n <SecretAccessKey>SECRET</SecretAccessKey>\n <SessionToken>TOKEN</SessionToken>\n <Expiration>1970-01-01T00:00:00.000Z</Expiration>\n </Credentials>\n </AssumeRoleResult>\n</AssumeRoleResponse>');
578+
creds = new AWS.SsoCredentials({
579+
httpOptions: {
580+
connectTimeout: 2000,
581+
proxy: 'https://foo.bar',
582+
timeout: 2000,
583+
}
584+
});
585+
httpClient = AWS.HttpClient.getInstance();
586+
spy = helpers.spyOn(httpClient, 'handleRequest').andCallThrough();
587+
return creds.refresh(function(err) {
588+
expect(spy.calls.length).to.equal(1);
589+
expect(spy.calls[0].arguments[1].connectTimeout).to.equal(2000);
590+
expect(spy.calls[0].arguments[1].proxy).to.equal('https://foo.bar');
591+
expect(spy.calls[0].arguments[1].timeout).to.equal(2000);
592+
return done();
593+
});
594+
});
575595
it('loads successfully while changing region and endpoint', function(done) {
576596
expect(creds.service.config.region).to.equal('us-east-1');
577597
expect(creds.service.config.endpoint).to.equal('portal.sso.us-east-1.amazonaws.com');

0 commit comments

Comments
 (0)