diff --git a/packages/api/src/utils/login.ts b/packages/api/src/utils/login.ts index a4a0236bb1..bd264e8028 100644 --- a/packages/api/src/utils/login.ts +++ b/packages/api/src/utils/login.ts @@ -10,18 +10,6 @@ import { TokenCredentialsBase } from "@azure/ms-rest-nodeauth"; * You can search at [Azure JS SDK](https://docs.microsoft.com/en-us/javascript/api/overview/azure/?view=azure-node-latest) to see which credential you need. */ export interface AzureAccountProvider { - /** - * @deprecated - * Get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) - * @param showDialog Control whether the UI layer displays pop-up windows. - */ - getAccountCredential(showDialog?: boolean): TokenCredentialsBase | undefined; - /** - * @deprecated - * Get identity [crendential](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts) - * @param showDialog Control whether the UI layer displays pop-up windows. - */ - getIdentityCredential(showDialog?: boolean): TokenCredential | undefined; /** * Async get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) * @param showDialog Control whether the UI layer displays pop-up windows. diff --git a/packages/api/tests/login.test.ts b/packages/api/tests/login.test.ts index f9ae8940d4..ef9d603245 100644 --- a/packages/api/tests/login.test.ts +++ b/packages/api/tests/login.test.ts @@ -15,12 +15,6 @@ class TestAzureAccountProvider implements AzureAccountProvider { getIdentityCredentialAsync(): Promise { throw new Error("getIdentityCredentialAsync Method not implemented."); } - getAccountCredential(): TokenCredentialsBase { - throw new Error("getAccountCredential Method not implemented."); - } - getIdentityCredential(): TokenCredential { - throw new Error("getIdentityCredential Method not implemented."); - } signout(): Promise { throw new Error("Method not implemented."); } @@ -98,24 +92,6 @@ class GraphProvider2 implements GraphTokenProvider { } } -describe("azureLogin", function () { - describe("withAzureAccountProvider", function () { - it("plugin context happy path", () => { - const azure = new TestAzureAccountProvider(); - try { - azure.getAccountCredential(); - } catch (error) { - assert.equal(error.message, "getAccountCredential Method not implemented."); - } - try { - azure.getIdentityCredential(); - } catch (error) { - assert.equal(error.message, "getIdentityCredential Method not implemented."); - } - }); - }); -}); - describe("graphLogin", function () { describe("withGraphProvider", function () { it("happy path", async () => { diff --git a/packages/cli/src/commonlib/azureLogin.ts b/packages/cli/src/commonlib/azureLogin.ts index 5341e72ed2..d995fb8db4 100644 --- a/packages/cli/src/commonlib/azureLogin.ts +++ b/packages/cli/src/commonlib/azureLogin.ts @@ -125,26 +125,6 @@ export class AzureAccountManager extends login implements AzureAccountProvider { return AzureAccountManager.instance; } - /** - * Get AccountCredential - * - Use scenario : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * - NPM guideline : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * @returns the instance of TokenCredentialsBase - */ - getAccountCredential(showDialog = true): TokenCredentialsBase | undefined { - throw new Error("Method not implemented."); - } - - /** - * Get IdentityCredential - * - Use scenario : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * - NPM guideline : https://www.npmjs.com/package/@azure/ms-rest-nodeauth - * @returns the instance of TokenCredential - */ - getIdentityCredential(showDialog = true): TokenCredential | undefined { - return undefined; - } - /** * Async get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) */ diff --git a/packages/cli/src/commonlib/azureLoginCI.ts b/packages/cli/src/commonlib/azureLoginCI.ts index b4390abd30..0d0a3669f5 100644 --- a/packages/cli/src/commonlib/azureLoginCI.ts +++ b/packages/cli/src/commonlib/azureLoginCI.ts @@ -41,19 +41,6 @@ export class AzureAccountManager extends login implements AzureAccountProvider { return AzureAccountManager.instance; } - /** - * Get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) - */ - getAccountCredential(): TokenCredentialsBase | undefined { - return AzureAccountManager.tokenCredentialsBase; - } - /** - * Get identity [crendential](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts) - */ - getIdentityCredential(): TokenCredential | undefined { - return AzureAccountManager.tokenCredential; - } - async getAccountCredentialAsync(): Promise { if (AzureAccountManager.tokenCredentialsBase == undefined) { const authres = await msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse( diff --git a/packages/cli/src/commonlib/azureLoginUserPassword.ts b/packages/cli/src/commonlib/azureLoginUserPassword.ts index 3eb10dc8cd..4686d4b99d 100644 --- a/packages/cli/src/commonlib/azureLoginUserPassword.ts +++ b/packages/cli/src/commonlib/azureLoginUserPassword.ts @@ -48,20 +48,6 @@ export class AzureAccountProviderUserPassword implements AzureAccountProvider { return AzureAccountProviderUserPassword.instance; } - /** - * Get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) - */ - getAccountCredential(): TokenCredentialsBase | undefined { - return AzureAccountProviderUserPassword.tokenCredentialsBase; - } - - /** - * Get identity [crendential](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-auth/src/tokenCredential.ts) - */ - getIdentityCredential(): TokenCredential | undefined { - return AzureAccountProviderUserPassword.tokenCredential; - } - async getAccountCredentialAsync(): Promise { if (AzureAccountProviderUserPassword.tokenCredentialsBase == undefined) { const authres = await msRestNodeAuth.loginWithUsernamePassword( diff --git a/packages/fx-core/src/core/index.ts b/packages/fx-core/src/core/index.ts index 522d7a7dda..16620b5bfb 100644 --- a/packages/fx-core/src/core/index.ts +++ b/packages/fx-core/src/core/index.ts @@ -651,7 +651,7 @@ class CoreImpl implements Core { let azureAccountLabel = "Sign in to Azure"; let azureAccountContextValue = "signinAzure"; - const token = this.ctx.azureAccountProvider?.getAccountCredential(); + const token = await this.ctx.azureAccountProvider?.getAccountCredentialAsync(); if (token !== undefined) { azureAccountLabel = (token as any).username ? (token as any).username : ""; azureAccountContextValue = "signedinAzure"; @@ -699,7 +699,7 @@ class CoreImpl implements Core { accountInfo?: Record | undefined ) => { if (status === "SignedIn") { - const token = this.ctx.azureAccountProvider?.getAccountCredential(); + const token = await this.ctx.azureAccountProvider?.getAccountCredentialAsync(); if (token !== undefined) { this.ctx.treeProvider?.refresh([ { diff --git a/packages/fx-core/tests/plugins/resource/apim/testUtil.ts b/packages/fx-core/tests/plugins/resource/apim/testUtil.ts index d57b7bf472..aba859ae82 100644 --- a/packages/fx-core/tests/plugins/resource/apim/testUtil.ts +++ b/packages/fx-core/tests/plugins/resource/apim/testUtil.ts @@ -105,14 +105,6 @@ export class MockAzureAccountProvider implements AzureAccountProvider { throw BuildError(NotImplemented); } - getAccountCredential(): TokenCredentialsBase | undefined { - throw BuildError(NotImplemented); - } - - getIdentityCredential(): TokenCredential | undefined { - throw BuildError(NotImplemented); - } - getJsonObject(showDialog?: boolean): Promise> { throw BuildError(NotImplemented); } diff --git a/packages/fx-core/tests/plugins/resource/bot/unit/utils.ts b/packages/fx-core/tests/plugins/resource/bot/unit/utils.ts index 3b24ffc903..b3be4f4580 100644 --- a/packages/fx-core/tests/plugins/resource/bot/unit/utils.ts +++ b/packages/fx-core/tests/plugins/resource/bot/unit/utils.ts @@ -177,12 +177,6 @@ export function newPluginContext(): PluginContext { }, }, azureAccountProvider: { - getAccountCredential: (showDialog?: boolean) => { - return undefined; - }, - getIdentityCredential: (showDialog?: boolean) => { - return undefined; - }, getAccountCredentialAsync: (showDialog?: boolean) => { return Promise.resolve(undefined); }, diff --git a/packages/fx-core/tests/plugins/resource/frontend/helper.ts b/packages/fx-core/tests/plugins/resource/frontend/helper.ts index 74389f61b8..d995cc6dd4 100644 --- a/packages/fx-core/tests/plugins/resource/frontend/helper.ts +++ b/packages/fx-core/tests/plugins/resource/frontend/helper.ts @@ -48,9 +48,6 @@ export class TestHelper { } as StorageAccountsCreateResponse; static fakeAzureAccountProvider: AzureAccountProvider = { - getAccountCredential: () => { - return TestHelper.fakeCredential; - }, getAccountCredentialAsync: async () => { return TestHelper.fakeCredential; }, diff --git a/packages/fx-core/tests/plugins/resource/function/unit/deploy.test.ts b/packages/fx-core/tests/plugins/resource/function/unit/deploy.test.ts index 7ba78fca59..2c43fb5c7b 100644 --- a/packages/fx-core/tests/plugins/resource/function/unit/deploy.test.ts +++ b/packages/fx-core/tests/plugins/resource/function/unit/deploy.test.ts @@ -76,11 +76,6 @@ const context: any = { }, config: new Map([["functionAppName", "ut"]]), azureAccountProvider: { - getAccountCredential: () => ({ - signRequest: () => { - return; - }, - }), getAccountCredentialAsync: async () => ({ signRequest: () => { return; diff --git a/packages/fx-core/tests/plugins/resource/function/unit/provision.test.ts b/packages/fx-core/tests/plugins/resource/function/unit/provision.test.ts index 4ac934bb86..decaef566a 100644 --- a/packages/fx-core/tests/plugins/resource/function/unit/provision.test.ts +++ b/packages/fx-core/tests/plugins/resource/function/unit/provision.test.ts @@ -85,11 +85,6 @@ const context: any = { }, }, azureAccountProvider: { - getAccountCredential: () => ({ - signRequest: () => { - return; - }, - }), getAccountCredentialAsync: async () => ({ signRequest: () => { return; diff --git a/packages/vscode-extension/src/commonlib/azureLogin.ts b/packages/vscode-extension/src/commonlib/azureLogin.ts index 3c5ae890db..0738ff03be 100644 --- a/packages/vscode-extension/src/commonlib/azureLogin.ts +++ b/packages/vscode-extension/src/commonlib/azureLogin.ts @@ -52,45 +52,6 @@ export class AzureAccountManager extends login implements AzureAccountProvider { return AzureAccountManager.instance; } - /** - * Get AccountCredential - * - Use scenario : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * - NPM guideline : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * @returns the instance of TokenCredentialsBase - */ - getAccountCredential(showDialog = true): TokenCredentialsBase | undefined { - const azureAccount: AzureAccount = - vscode.extensions.getExtension("ms-vscode.azure-account")!.exports; - if (azureAccount.status === "LoggedIn") { - if (azureAccount.subscriptions.length > 0) { - if (AzureAccountManager.tenantId) { - for (let i = 0; i < azureAccount.sessions.length; ++i) { - const item = azureAccount.sessions[i]; - if (item.tenantId == AzureAccountManager.tenantId) { - return item.credentials2; - } - } - } - return azureAccount.subscriptions[0].session.credentials2; - } else if (azureAccount.sessions.length > 0) { - return azureAccount.sessions[0].credentials2; - } else { - return undefined; - } - } - return undefined; - } - - /** - * Get IdentityCredential - * - Use scenario : https://docs.microsoft.com/en-us/azure/developer/javascript/core/node-sdk-azure-authenticate - * - NPM guideline : https://www.npmjs.com/package/@azure/ms-rest-nodeauth - * @returns the instance of TokenCredential - */ - getIdentityCredential(showDialog = true): TokenCredential | undefined { - throw new Error("Method not implemented."); - } - /** * Async get ms-rest-* [credential](https://github.com/Azure/ms-rest-nodeauth/blob/master/lib/credentials/tokenCredentialsBase.ts) */ diff --git a/packages/vscode-extension/src/controls/webviewPanel.ts b/packages/vscode-extension/src/controls/webviewPanel.ts index ec85d7b972..d3a1f2882f 100644 --- a/packages/vscode-extension/src/controls/webviewPanel.ts +++ b/packages/vscode-extension/src/controls/webviewPanel.ts @@ -184,10 +184,10 @@ export class WebviewPanel { } ); - AzureAccountManager.setStatusChangeMap("quick-start-webview", (status, token, accountInfo) => { + AzureAccountManager.setStatusChangeMap("quick-start-webview", async (status, token, accountInfo) => { let email = undefined; if (status === "SignedIn") { - const token = AzureAccountManager.getAccountCredential(); + const token = await AzureAccountManager.getAccountCredentialAsync(); if (token !== undefined) { email = (token as any).username ? (token as any).username : undefined; } diff --git a/packages/vscode-extension/test/suite/integration/extension.noFolder.test.ts b/packages/vscode-extension/test/suite/integration/extension.noFolder.test.ts index d4bcac6046..88ab231f2d 100644 --- a/packages/vscode-extension/test/suite/integration/extension.noFolder.test.ts +++ b/packages/vscode-extension/test/suite/integration/extension.noFolder.test.ts @@ -32,8 +32,6 @@ suite("Extension Integration Tests (No Folder)", async () => { }); // test("Login test", async function (this: Mocha.Context) { - // var accountCrendential = AzureAccountManager.getInstance().getAccountCredential(); - // var identityCredential = AzureAccountManager.getInstance().getIdentityCredential(); // chai.assert.equal(true, typeof(accountCrendential)!==null); // chai.assert.equal(true, typeof(identityCredential)!==null); // });