Skip to content

Commit 1fb9e4e

Browse files
committed
add more mfa feature
1 parent 65a8a80 commit 1fb9e4e

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

packages/amazonq/src/lsp/client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
updateConfigurationRequestType,
3333
GetMfaCodeParams,
3434
GetMfaCodeResult,
35-
getMfaCodeRequestType,
3635
} from '@aws/language-server-runtimes/protocol'
3736
import {
3837
AuthUtil,
@@ -59,7 +58,7 @@ import { processUtils } from 'aws-core-vscode/shared'
5958
import { activate as activateChat } from './chat/activation'
6059
import { activate as activeInlineChat } from '../inlineChat/activation'
6160
import { AmazonQResourcePaths } from './lspInstaller'
62-
import { auth2 } from 'aws-core-vscode/auth'
61+
import { auth2, getMfaTokenFromUser } from 'aws-core-vscode/auth'
6362
import { ConfigSection, isValidConfigSection, pushConfigUpdate, toAmazonQLSPLogLevel } from './config'
6463
import { telemetry } from 'aws-core-vscode/telemetry'
6564
import { SessionManager } from '../app/inline/sessionManager'
@@ -346,10 +345,10 @@ async function postStartLanguageServer(
346345
)
347346

348347
// Handler for when Flare needs to assume a role with MFA code
349-
client.onRequest<GetMfaCodeParams, GetMfaCodeResult>(
350-
getMfaCodeRequestType.method,
348+
client.onRequest(
349+
auth2.notificationTypes.getMfaCode.method,
351350
async (params: GetMfaCodeParams): Promise<GetMfaCodeResult> => {
352-
const mfaCode = await vscode.window.showInputBox({ title: 'Enter MFA Code' })
351+
const mfaCode = await getMfaTokenFromUser(params.mfaSerial, params.profileName)
353352
return { code: mfaCode ?? '' }
354353
}
355354
)

packages/core/src/auth/auth2.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ import {
4949
iamCredentialsUpdateRequestType,
5050
Profile,
5151
SsoSession,
52+
GetMfaCodeParams,
53+
getMfaCodeRequestType,
54+
5255
} from '@aws/language-server-runtimes/protocol'
5356
import { LanguageClient } from 'vscode-languageclient'
5457
import { getLogger } from '../shared/logger/logger'
@@ -70,6 +73,9 @@ export const notificationTypes = {
7073
getConnectionMetadata: new RequestType<undefined, ConnectionMetadata, Error>(
7174
getConnectionMetadataRequestType.method
7275
),
76+
getMfaCode: new RequestType<GetMfaCodeParams, ResponseMessage, Error>(
77+
getMfaCodeRequestType.method
78+
)
7379
}
7480

7581
export type AuthState = 'notConnected' | 'connected' | 'expired'

packages/core/src/auth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export {
2222
} from './connection'
2323
export { Auth } from './auth'
2424
export { CredentialsStore } from './credentials/store'
25+
export { getMfaTokenFromUser } from './credentials/utils'
2526
export { LoginManager } from './deprecated/loginManager'
2627
export * as constants from './sso/constants'
2728
export * as cache from './sso/cache'

packages/core/src/test/credentials/auth2.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,22 @@ describe('LanguageClientAuth', () => {
102102
sso_region: region,
103103
})
104104
})
105+
106+
it('sends correct IAM profile update parameters', async () => {
107+
await auth.updateIamProfile(profileName, 'accessKey', 'secretKey', 'sessionToken')
108+
109+
sinon.assert.calledOnce(client.sendRequest)
110+
const requestParams = client.sendRequest.firstCall.args[1]
111+
sinon.assert.match(requestParams.profile, {
112+
name: profileName,
113+
kinds: [ProfileKind.IamCredentialsProfile],
114+
})
115+
sinon.assert.match(requestParams.profile.settings, {
116+
aws_access_key_id: 'accessKey',
117+
aws_secret_access_key: 'secretKey',
118+
aws_session_token: 'sessionToken',
119+
})
120+
})
105121
})
106122

107123
describe('getProfile', () => {

0 commit comments

Comments
 (0)