Skip to content

Commit f5498c3

Browse files
fix(auth): SSO failed to get token due to missing 'refreshToken'
Problem: Error users were seeing was: ``` Error: SSO cache data unexpectedly missing props: ["refreshToken"] ``` This was due to a check in a previos 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 check that the refreshToken exists, but it keeps the validation that the accessToken exists since that is always guaranteed. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 2af8b45 commit f5498c3

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-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
}

0 commit comments

Comments
 (0)