Skip to content

Commit

Permalink
auth: Check if tenant is signed in before listing subscriptions (#1585)
Browse files Browse the repository at this point in the history
* auth: Check if tenant is signed in before listing subscriptions

* Bump version
  • Loading branch information
alexweininger authored Sep 14, 2023
1 parent d3a81b5 commit 171a189
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 9 additions & 2 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<boolean> {
const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getDefaultScopes(), { createIfNone: false, silent: true });
public async isSignedIn(tenantId?: string): Promise<boolean> {
const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getScopes([], tenantId), { createIfNone: false, silent: true });
return !!session;
}

Expand Down

0 comments on commit 171a189

Please sign in to comment.