Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/core/src/auth/sso/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getLogger } from '../../shared/logger/logger'
import fs from '../../shared/fs/fs'
import { createDiskCache, KeyedCache, mapCache } from '../../shared/utilities/cacheUtils'
import { stripUndefined } from '../../shared/utilities/collectionUtils'
import { getMissingProps, hasProps, selectFrom } from '../../shared/utilities/tsUtils'
import { hasProps, selectFrom } from '../../shared/utilities/tsUtils'
import { SsoToken, ClientRegistration } from './model'
import { DevSettings } from '../../shared/settings'
import { onceChanged } from '../../shared/utilities/functionUtils'
Expand Down Expand Up @@ -79,6 +79,11 @@ export function getTokenCache(directory = getCacheDir()): KeyedCache<SsoAccess>
}

function read(data: StoredToken): SsoAccess {
// Validate data is not missing. Since the input data is passed directly from whatever is on disk.
if (!hasProps(data, 'accessToken')) {
throw new ToolkitError(`SSO cache data looks malformed`)
}

const registration = hasProps(data, 'clientId', 'clientSecret', 'registrationExpiresAt')
? {
...selectFrom(data, 'clientId', 'clientSecret', 'scopes', 'startUrl'),
Expand All @@ -93,12 +98,6 @@ export function getTokenCache(directory = getCacheDir()): KeyedCache<SsoAccess>

stripUndefined(token)

// Validate data is not missing.
const missingProps = getMissingProps(token, 'accessToken', 'refreshToken')
if (missingProps.length > 0) {
throw new ToolkitError(`SSO cache data unexpectedly missing props: ${JSON.stringify(missingProps)}`)
}

return {
token,
registration,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/test/credentials/sso/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('SSO Cache', function () {
const validToken = {
accessToken: 'longstringofrandomcharacters',
expiresAt: new Date(Date.now() + hourInMs),
refreshToken: 'dummyRefreshToken',
} as SsoToken

beforeEach(async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ describe('SsoAccessTokenProvider', function () {
return {
accessToken: 'dummyAccessToken',
expiresAt: new clock.Date(clock.Date.now() + timeDelta),
refreshToken: 'dummyRefreshToken',
...extras,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Auth: SSO failed to missing refreshToken"
}
Loading