From 171a1898cc962ba524c0840762dd8e290b262c78 Mon Sep 17 00:00:00 2001 From: Alex Weininger Date: Thu, 14 Sep 2023 09:59:45 -0700 Subject: [PATCH] auth: Check if tenant is signed in before listing subscriptions (#1585) * auth: Check if tenant is signed in before listing subscriptions * Bump version --- auth/package-lock.json | 4 ++-- auth/package.json | 2 +- auth/src/VSCodeAzureSubscriptionProvider.ts | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/auth/package-lock.json b/auth/package-lock.json index e8a8c9d1d8..7533d86c3f 100644 --- a/auth/package-lock.json +++ b/auth/package-lock.json @@ -1,12 +1,12 @@ { "name": "@microsoft/vscode-azext-azureauth", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@microsoft/vscode-azext-azureauth", - "version": "1.1.2", + "version": "1.1.3", "license": "MIT", "dependencies": { "@azure/arm-subscriptions": "^5.1.0", diff --git a/auth/package.json b/auth/package.json index 62c50ab8b9..b1abcb4338 100644 --- a/auth/package.json +++ b/auth/package.json @@ -1,7 +1,7 @@ { "name": "@microsoft/vscode-azext-azureauth", "author": "Microsoft Corporation", - "version": "1.1.2", + "version": "1.1.3", "description": "Azure authentication helpers for Visual Studio Code", "tags": [ "azure", diff --git a/auth/src/VSCodeAzureSubscriptionProvider.ts b/auth/src/VSCodeAzureSubscriptionProvider.ts index f2dc8b99e5..f7d4bd964a 100644 --- a/auth/src/VSCodeAzureSubscriptionProvider.ts +++ b/auth/src/VSCodeAzureSubscriptionProvider.ts @@ -85,6 +85,11 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement continue; } + // If the user is not signed in to this tenant, then skip it + if (!(await this.isSignedIn(tenantId))) { + continue; + } + // For each tenant, get the list of subscriptions for (const subscription of await this.getSubscriptionsForTenant(tenantId)) { // If filtering is enabled, and the current subscription is not in that list, then skip it @@ -105,10 +110,12 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement /** * Checks to see if a user is signed in. * + * @param tenantId (Optional) Provide to check if a user is signed in to a specific tenant. + * * @returns True if the user is signed in, false otherwise. */ - public async isSignedIn(): Promise { - const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getDefaultScopes(), { createIfNone: false, silent: true }); + public async isSignedIn(tenantId?: string): Promise { + const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getScopes([], tenantId), { createIfNone: false, silent: true }); return !!session; }