Skip to content

Commit 01ec7f5

Browse files
committed
fix: support tokens by not overwriting with shim
1 parent 30dbd59 commit 01ec7f5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/core/src/shared/awsClientBuilderV3.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ export class AWSClientBuilderV3 {
160160
if (!opt.requestHandler) {
161161
opt.requestHandler = this.getHttpHandler()
162162
}
163-
// TODO: add tests for refresh logic.
164-
opt.credentials = async () => {
165-
const creds = await shim.get()
166-
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
167-
return shim.refresh()
163+
164+
if (!opt.credentials && !opt.token) {
165+
opt.credentials = async () => {
166+
const creds = await shim.get()
167+
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
168+
return shim.refresh()
169+
}
170+
return creds
168171
}
169-
return creds
170172
}
171173

172174
const service = new serviceOptions.serviceClient(opt)

packages/core/src/test/shared/awsClientBuilderV3.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ describe('AwsClientBuilderV3', function () {
329329
mockCredsShim.update(newerCreds)
330330
assert.strictEqual(await service.config.credentials(), newerCreds)
331331
})
332+
333+
it('does not initialize credentials if token is provided', function () {
334+
const service = builder.createAwsService({
335+
serviceClient: Client,
336+
clientOptions: {
337+
token: { token: 'my-token', expiration: new Date(Date.now() + oneDay) },
338+
},
339+
})
340+
assert.ok(service.config.credentials === undefined)
341+
})
332342
})
333343
})
334344

0 commit comments

Comments
 (0)