Skip to content

Commit d153e1e

Browse files
authored
fix(auth): refresh credentials on some API errors #2712
Problem: JS SDK v2 has built-in logic to 'refresh' credentials on certain API errors, but the way it works is that it directly mutates the credentials provider. Solution: Align with the implementation. This should _finally_ resolve this fairly long-standing bug. Related: * #2664 * #2465 * #1226
1 parent 319cddf commit d153e1e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Credentials are now automatically refreshed on certain AWS API errors"
4+
}

src/shared/awsClientBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ export class DefaultAWSClientBuilder implements AWSClientBuilder {
104104
shim.refresh()
105105
.then(creds => {
106106
this.loadCreds(creds)
107+
// The SDK V2 sets `expired` on certain errors so we should only
108+
// unset the flag after acquiring new credentials via `refresh`
109+
this.expired = false
107110
callback()
108111
})
109112
.catch(callback)
110113
}
111114

112115
private loadCreds(creds: CredentialsOptions & { expiration?: Date }) {
113-
this.expired = false
114116
this.accessKeyId = creds.accessKeyId
115117
this.secretAccessKey = creds.secretAccessKey
116118
this.sessionToken = creds.sessionToken ?? this.sessionToken

0 commit comments

Comments
 (0)