Skip to content

Commit f012db8

Browse files
authored
credentials: Reconnect to SSO profile (#2013)
Problem: SSO profiles do not reconnect automatically on start up, even if the token is still valid. Solution: If the most recent credentials were a SSO profile, check if the token is still valid. Continue login if it is, but do not attempt to refresh if the token is no longer valid.
1 parent 75a635e commit f012db8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Credentials: SSO profiles will reconnect on startup if the token is still valid"
4+
}

src/credentials/providers/sharedCredentialsProvider.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ export class SharedCredentialsProvider implements CredentialsProvider {
104104
}
105105

106106
public canAutoConnect(): boolean {
107-
return !hasProfileProperty(this.profile, SHARED_CREDENTIAL_PROPERTIES.MFA_SERIAL) && !this.isSsoProfile()
107+
// check if SSO token is still valid
108+
if (this.isSsoProfile()) {
109+
return !!new DiskCache().loadAccessToken(this.profile[SHARED_CREDENTIAL_PROPERTIES.SSO_START_URL]!)
110+
}
111+
return !hasProfileProperty(this.profile, SHARED_CREDENTIAL_PROPERTIES.MFA_SERIAL)
108112
}
109113

110114
public async isAvailable(): Promise<boolean> {
@@ -152,7 +156,7 @@ export class SharedCredentialsProvider implements CredentialsProvider {
152156

153157
/**
154158
* Patches 'source_profile' credentials as static representations, which the SDK can handle in all cases.
155-
*
159+
*
156160
* XXX: Returns undefined if no `source_profile` property exists. Else we would prevent the SDK from re-reading
157161
* the shared credential files if they were to change. #1953
158162
*

0 commit comments

Comments
 (0)