@@ -99,6 +99,7 @@ import { ClientWrapper } from './clientWrapper'
9999import { StandardRetryStrategy } from '@smithy/util-retry'
100100import { ServiceException } from '@aws-sdk/smithy-client'
101101import { AccessDeniedException } from '@aws-sdk/client-sso-oidc'
102+ import { TokenIdentityProvider } from '@aws-sdk/types'
102103
103104const requiredDevEnvProps = [
104105 'id' ,
@@ -231,7 +232,7 @@ async function createCodeCatalystClient(
231232}
232233
233234function createCodeCatalystClientV3 (
234- tokenProvider : TokenProvider ,
235+ tokenProvider : TokenIdentityProvider ,
235236 regionCode : string ,
236237 endpoint : string ,
237238 maxRetries : number
@@ -266,7 +267,6 @@ export const onAccessDeniedException = onAccessDeniedExceptionEmitter.event
266267interface AuthOptions {
267268 showReauthPrompt ?: boolean
268269}
269-
270270export type CodeCatalystClientFactory = ( ) => Promise < CodeCatalystClient >
271271/**
272272 * Factory to create a new `CodeCatalystClient`. Call `onCredentialsChanged()` before making requests.
@@ -280,7 +280,7 @@ export async function createClient(
280280) : Promise < CodeCatalystClient > {
281281 const tokenProvider = new TokenProvider ( connection )
282282 const sdkClient = await createCodeCatalystClient ( tokenProvider , regionCode , endpoint , maxRetries )
283- const sdkv3Client = createCodeCatalystClientV3 ( tokenProvider , regionCode , endpoint , maxRetries )
283+ const sdkv3Client = createCodeCatalystClientV3 ( getTokenProvider ( connection ) , regionCode , endpoint , maxRetries )
284284 const c = new CodeCatalystClientInternal ( connection , sdkClient , sdkv3Client )
285285 try {
286286 await c . verifySession ( )
@@ -297,6 +297,17 @@ export async function createClient(
297297 return c
298298}
299299
300+ // TODO: move this to sso auth folder?
301+ function getTokenProvider ( connection : SsoConnection ) : TokenIdentityProvider {
302+ return async ( _props ) => {
303+ const token = await connection . getToken ( )
304+ return {
305+ token : token . accessToken ,
306+ expiration : token . expiresAt ,
307+ }
308+ }
309+ }
310+
300311// XXX: the backend currently rejects empty strings for `alias` so the field must be removed if falsey
301312function fixAliasInRequest < T extends CreateDevEnvironmentRequest | UpdateDevEnvironmentRequest > ( request : T ) : T {
302313 if ( ! request . alias ) {
@@ -533,16 +544,17 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
533544 if ( CodeCatalystClientInternal . identityCache . has ( accessToken ) ) {
534545 return CodeCatalystClientInternal . identityCache . get ( accessToken ) !
535546 }
536- const resp : VerifySessionCommandOutput = await this . callV3 ( VerifySessionCommand , { } , false )
537- assertHasProps ( resp , 'identity' )
538547
539- CodeCatalystClientInternal . identityCache . set ( accessToken , resp . identity )
548+ const r : VerifySessionCommandOutput = await this . callV3 ( VerifySessionCommand , { } , false )
549+ assertHasProps ( r , 'identity' )
550+
551+ CodeCatalystClientInternal . identityCache . set ( accessToken , r . identity )
540552 setTimeout ( ( ) => {
541553 CodeCatalystClientInternal . identityCache . delete ( accessToken )
542- CodeCatalystClientInternal . userDetailsCache . delete ( resp . identity )
554+ CodeCatalystClientInternal . userDetailsCache . delete ( r . identity )
543555 } , expiresAt . getTime ( ) - Date . now ( ) )
544556
545- return resp . identity
557+ return r . identity
546558 }
547559
548560 public async getBearerToken ( ) : Promise < string > {
0 commit comments