Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove login sync #1209

Merged
merged 3 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions packages/api/src/utils/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 0 additions & 24 deletions packages/api/tests/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ class TestAzureAccountProvider implements AzureAccountProvider {
getIdentityCredentialAsync(): Promise<TokenCredential | undefined> {
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<boolean> {
throw new Error("Method not implemented.");
}
Expand Down Expand Up @@ -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 () => {
Expand Down
20 changes: 0 additions & 20 deletions packages/cli/src/commonlib/azureLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
13 changes: 0 additions & 13 deletions packages/cli/src/commonlib/azureLoginCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenCredentialsBase | undefined> {
if (AzureAccountManager.tokenCredentialsBase == undefined) {
const authres = await msRestNodeAuth.loginWithServicePrincipalSecretWithAuthResponse(
Expand Down
14 changes: 0 additions & 14 deletions packages/cli/src/commonlib/azureLoginUserPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenCredentialsBase | undefined> {
if (AzureAccountProviderUserPassword.tokenCredentialsBase == undefined) {
const authres = await msRestNodeAuth.loginWithUsernamePassword(
Expand Down
4 changes: 2 additions & 2 deletions packages/fx-core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -699,7 +699,7 @@ class CoreImpl implements Core {
accountInfo?: Record<string, unknown> | undefined
) => {
if (status === "SignedIn") {
const token = this.ctx.azureAccountProvider?.getAccountCredential();
const token = await this.ctx.azureAccountProvider?.getAccountCredentialAsync();
if (token !== undefined) {
this.ctx.treeProvider?.refresh([
{
Expand Down
8 changes: 0 additions & 8 deletions packages/fx-core/tests/plugins/resource/apim/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, unknown>> {
throw BuildError(NotImplemented);
}
Expand Down
6 changes: 0 additions & 6 deletions packages/fx-core/tests/plugins/resource/bot/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
3 changes: 0 additions & 3 deletions packages/fx-core/tests/plugins/resource/frontend/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ export class TestHelper {
} as StorageAccountsCreateResponse;

static fakeAzureAccountProvider: AzureAccountProvider = {
getAccountCredential: () => {
return TestHelper.fakeCredential;
},
getAccountCredentialAsync: async () => {
return TestHelper.fakeCredential;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ const context: any = {
},
config: new Map<string, string>([["functionAppName", "ut"]]),
azureAccountProvider: {
getAccountCredential: () => ({
signRequest: () => {
return;
},
}),
getAccountCredentialAsync: async () => ({
signRequest: () => {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ const context: any = {
},
},
azureAccountProvider: {
getAccountCredential: () => ({
signRequest: () => {
return;
},
}),
getAccountCredentialAsync: async () => ({
signRequest: () => {
return;
Expand Down
39 changes: 0 additions & 39 deletions packages/vscode-extension/src/commonlib/azureLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AzureAccount>("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)
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/controls/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// });
Expand Down