@@ -57,7 +57,7 @@ import { LanguageClient } from 'vscode-languageclient'
57
57
import { getLogger } from '../shared/logger/logger'
58
58
import { ToolkitError } from '../shared/errors'
59
59
import { useDeviceFlow } from './sso/ssoAccessTokenProvider'
60
- import { getCacheDir , getCacheFileWatcher , getFlareCacheFileName } from './sso/cache'
60
+ import { getCacheDir , getCacheFileWatcher , getFlareCacheFileName , getStsCacheDir } from './sso/cache'
61
61
import { VSCODE_EXTENSION_ID } from '../shared/extensions'
62
62
import { IamCredentials } from '@aws/language-server-runtimes-types'
63
63
import globals from '../shared/extensionGlobals'
@@ -75,6 +75,7 @@ export const notificationTypes = {
75
75
getConnectionMetadata : new RequestType < undefined , ConnectionMetadata , Error > (
76
76
getConnectionMetadataRequestType . method
77
77
) ,
78
+ getMfaCode : new RequestType < GetMfaCodeParams , ResponseMessage , Error > ( getMfaCodeRequestType . method ) ,
78
79
}
79
80
80
81
export type AuthState = 'notConnected' | 'connected' | 'expired'
@@ -89,6 +90,8 @@ export type LoginType = (typeof LoginTypes)[keyof typeof LoginTypes]
89
90
90
91
export type cacheChangedEvent = 'delete' | 'create'
91
92
93
+ export type stsCacheChangedEvent = 'delete' | 'create'
94
+
92
95
export type Login = SsoLogin | IamLogin
93
96
94
97
export type TokenSource = IamIdentityCenterSsoTokenSource | AwsBuilderIdSsoTokenSource
@@ -114,6 +117,10 @@ const IamProfileOptionsDefaults = {
114
117
*/
115
118
export class LanguageClientAuth {
116
119
readonly #ssoCacheWatcher = getCacheFileWatcher ( getCacheDir ( ) , getFlareCacheFileName ( VSCODE_EXTENSION_ID . amazonq ) )
120
+ readonly #stsCacheWatcher = getCacheFileWatcher (
121
+ getStsCacheDir ( ) ,
122
+ getFlareCacheFileName ( VSCODE_EXTENSION_ID . amazonq )
123
+ )
117
124
118
125
constructor (
119
126
private readonly client : LanguageClient ,
@@ -125,6 +132,10 @@ export class LanguageClientAuth {
125
132
return this . #ssoCacheWatcher
126
133
}
127
134
135
+ public get stsCacheWatcher ( ) {
136
+ return this . #stsCacheWatcher
137
+ }
138
+
128
139
getSsoToken (
129
140
tokenSource : TokenSource ,
130
141
login : boolean = false ,
@@ -281,6 +292,11 @@ export class LanguageClientAuth {
281
292
this . cacheWatcher . onDidCreate ( ( ) => cacheChangedHandler ( 'create' ) )
282
293
this . cacheWatcher . onDidDelete ( ( ) => cacheChangedHandler ( 'delete' ) )
283
294
}
295
+
296
+ registerStsCacheWatcher ( stsCacheChangedHandler : ( event : stsCacheChangedEvent ) => any ) {
297
+ this . stsCacheWatcher . onDidCreate ( ( ) => stsCacheChangedHandler ( 'create' ) )
298
+ this . stsCacheWatcher . onDidDelete ( ( ) => stsCacheChangedHandler ( 'delete' ) )
299
+ }
284
300
}
285
301
286
302
/**
@@ -357,13 +373,8 @@ export abstract class BaseLogin {
357
373
* Decrypts an encrypted string, removes its quotes, and returns the resulting string
358
374
*/
359
375
protected async decrypt ( encrypted : string ) : Promise < string > {
360
- try {
361
- const decrypted = await jose . compactDecrypt ( encrypted , this . lspAuth . encryptionKey )
362
- return decrypted . plaintext . toString ( ) . replaceAll ( '"' , '' )
363
- } catch ( e ) {
364
- getLogger ( ) . error ( `Failed to decrypt: ${ encrypted } ` )
365
- return encrypted
366
- }
376
+ const decrypted = await jose . compactDecrypt ( encrypted , this . lspAuth . encryptionKey )
377
+ return decrypted . plaintext . toString ( ) . replaceAll ( '"' , '' )
367
378
}
368
379
}
369
380
@@ -575,14 +586,6 @@ export class IamLogin extends BaseLogin {
575
586
* Restore the connection state and connection details to memory, if they exist.
576
587
*/
577
588
async restore ( ) {
578
- const sessionData = await this . getProfile ( )
579
- const credentials = sessionData ?. profile ?. settings
580
- if ( credentials ?. aws_access_key_id && credentials ?. aws_secret_access_key ) {
581
- this . _data = {
582
- accessKey : credentials . aws_access_key_id ,
583
- secretKey : credentials . aws_secret_access_key ,
584
- }
585
- }
586
589
try {
587
590
await this . _getIamCredential ( false )
588
591
} catch ( err ) {
0 commit comments