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

auth: Check if tenant is signed in before listing subscriptions #1585

Merged
merged 2 commits into from
Sep 14, 2023
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
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