Skip to content

Commit fc740fa

Browse files
committed
add more mfa feature
1 parent 8c014b7 commit fc740fa

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
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: 9 additions & 3 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'
@@ -140,7 +146,7 @@ export class LanguageClientAuth {
140146
{
141147
profileName: profileName,
142148
options: {
143-
generateOnInvalidStsCredential: login,
149+
callStsOnInvalidIamCredential: login,
144150
},
145151
} satisfies GetIamCredentialParams,
146152
cancellationToken
@@ -182,7 +188,7 @@ export class LanguageClientAuth {
182188
let profile: Profile
183189
if (roleArn) {
184190
profile = {
185-
kinds: [ProfileKind.IamRoleSourceProfile],
191+
kinds: [ProfileKind.IamSourceProfileProfile],
186192
name: profileName,
187193
settings: {
188194
sso_session: '',
@@ -195,7 +201,7 @@ export class LanguageClientAuth {
195201
}
196202
} else if (accessKey && secretKey) {
197203
profile = {
198-
kinds: [ProfileKind.IamUserProfile],
204+
kinds: [ProfileKind.IamCredentialsProfile],
199205
name: profileName,
200206
settings: {
201207
sso_session: '',

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('LanguageClientAuth', () => {
110110
const requestParams = client.sendRequest.firstCall.args[1]
111111
sinon.assert.match(requestParams.profile, {
112112
name: profileName,
113-
kinds: [ProfileKind.IamUserProfile],
113+
kinds: [ProfileKind.IamCredentialsProfile],
114114
})
115115
sinon.assert.match(requestParams.profile.settings, {
116116
aws_access_key_id: 'accessKey',

0 commit comments

Comments
 (0)