Skip to content

Commit 96ce5ae

Browse files
fix(auth): SSO failed to get token due to missing 'refreshToken' (#6234)
## Problem: Error users were seeing was: ``` Error: SSO cache data unexpectedly missing props: ["refreshToken"] ``` This was due to a change from a previous PR that assumed the refreshToken was always present in SSO cache. ## Solution: It looks like the refreshToken does not exist for all cases, so some research needs to be done. But for now this reverts the validation that the refreshToken exists. Though it keeps the validation that the accessToken exists since that is always guaranteed. **A temporary workaround should be to sign out/in and things should start working. If not please downgrade 3.38.0 until we release this fix next week.** Fixes #6230 --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 5b5df85 commit 96ce5ae

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

packages/core/src/auth/sso/cache.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getLogger } from '../../shared/logger/logger'
1010
import fs from '../../shared/fs/fs'
1111
import { createDiskCache, KeyedCache, mapCache } from '../../shared/utilities/cacheUtils'
1212
import { stripUndefined } from '../../shared/utilities/collectionUtils'
13-
import { getMissingProps, hasProps, selectFrom } from '../../shared/utilities/tsUtils'
13+
import { hasProps, selectFrom } from '../../shared/utilities/tsUtils'
1414
import { SsoToken, ClientRegistration } from './model'
1515
import { DevSettings } from '../../shared/settings'
1616
import { onceChanged } from '../../shared/utilities/functionUtils'
@@ -79,6 +79,11 @@ export function getTokenCache(directory = getCacheDir()): KeyedCache<SsoAccess>
7979
}
8080

8181
function read(data: StoredToken): SsoAccess {
82+
// Validate data is not missing. Since the input data is passed directly from whatever is on disk.
83+
if (!hasProps(data, 'accessToken')) {
84+
throw new ToolkitError(`SSO cache data looks malformed`)
85+
}
86+
8287
const registration = hasProps(data, 'clientId', 'clientSecret', 'registrationExpiresAt')
8388
? {
8489
...selectFrom(data, 'clientId', 'clientSecret', 'scopes', 'startUrl'),
@@ -93,12 +98,6 @@ export function getTokenCache(directory = getCacheDir()): KeyedCache<SsoAccess>
9398

9499
stripUndefined(token)
95100

96-
// Validate data is not missing.
97-
const missingProps = getMissingProps(token, 'accessToken', 'refreshToken')
98-
if (missingProps.length > 0) {
99-
throw new ToolkitError(`SSO cache data unexpectedly missing props: ${JSON.stringify(missingProps)}`)
100-
}
101-
102101
return {
103102
token,
104103
registration,

packages/core/src/test/credentials/sso/cache.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe('SSO Cache', function () {
2727
const validToken = {
2828
accessToken: 'longstringofrandomcharacters',
2929
expiresAt: new Date(Date.now() + hourInMs),
30-
refreshToken: 'dummyRefreshToken',
3130
} as SsoToken
3231

3332
beforeEach(async function () {

packages/core/src/test/credentials/sso/ssoAccessTokenProvider.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe('SsoAccessTokenProvider', function () {
4545
return {
4646
accessToken: 'dummyAccessToken',
4747
expiresAt: new clock.Date(clock.Date.now() + timeDelta),
48-
refreshToken: 'dummyRefreshToken',
4948
...extras,
5049
}
5150
}
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": "Auth: SSO failed to missing refreshToken"
4+
}

0 commit comments

Comments
 (0)