diff --git a/auth/src/AzureDevOpsSubscriptionProvider.ts b/auth/src/AzureDevOpsSubscriptionProvider.ts index 757d6b4492..dc6306e0d4 100644 --- a/auth/src/AzureDevOpsSubscriptionProvider.ts +++ b/auth/src/AzureDevOpsSubscriptionProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-resources-subscriptions'; +import type { SubscriptionClient } from '@azure/arm-resources-subscriptions'; import type { TokenCredential } from '@azure/core-auth'; // Keep this as `import type` to avoid actually loading the package (at all, this one is dev-only) import type { PipelineRequest } from '@azure/core-rest-pipeline'; import { Disposable, Event } from 'vscode'; @@ -11,6 +11,7 @@ import { AzureAuthentication } from './AzureAuthentication'; import { AzureSubscription } from './AzureSubscription'; import { AzureSubscriptionProvider } from './AzureSubscriptionProvider'; import { getConfiguredAzureEnv } from './utils/configuredAzureEnv'; +import { AzureTenant } from './AzureTenant'; export interface AzureDevOpsSubscriptionProviderInitializer { /** @@ -102,9 +103,13 @@ export class AzureDevOpsSubscriptionProvider implements AzureSubscriptionProvide this._tokenCredential = undefined; } - public async getTenants(): Promise { + public async getTenants(): Promise { return [{ tenantId: this._tokenCredential?.tenantId, + account: { + id: "test-account-id", + label: "test-account", + } }]; } diff --git a/auth/src/AzureSubscriptionProvider.ts b/auth/src/AzureSubscriptionProvider.ts index e0069255ab..0ea1cb5be1 100644 --- a/auth/src/AzureSubscriptionProvider.ts +++ b/auth/src/AzureSubscriptionProvider.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { TenantIdDescription } from '@azure/arm-resources-subscriptions'; import type * as vscode from 'vscode'; import type { AzureSubscription } from './AzureSubscription'; +import type { AzureTenant } from './AzureTenant'; /** * An interface for obtaining Azure subscription information @@ -19,7 +19,7 @@ export interface AzureSubscriptionProvider { * * @returns A list of tenants. */ - getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise; + getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise; /** * Gets a list of Azure subscriptions available to the user. diff --git a/auth/src/AzureTenant.ts b/auth/src/AzureTenant.ts new file mode 100644 index 0000000000..5c1a6490f3 --- /dev/null +++ b/auth/src/AzureTenant.ts @@ -0,0 +1,11 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { TenantIdDescription } from "@azure/arm-resources-subscriptions"; +import * as vscode from 'vscode'; + +export interface AzureTenant extends TenantIdDescription { + account: vscode.AuthenticationSessionAccountInformation; +} diff --git a/auth/src/VSCodeAzureSubscriptionProvider.ts b/auth/src/VSCodeAzureSubscriptionProvider.ts index a27620284a..795bb5a360 100644 --- a/auth/src/VSCodeAzureSubscriptionProvider.ts +++ b/auth/src/VSCodeAzureSubscriptionProvider.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-resources-subscriptions'; // Keep this as `import type` to avoid actually loading the package before necessary +import type { SubscriptionClient } from '@azure/arm-resources-subscriptions'; // Keep this as `import type` to avoid actually loading the package before necessary import type { TokenCredential } from '@azure/core-auth'; // Keep this as `import type` to avoid actually loading the package (at all, this one is dev-only) import * as vscode from 'vscode'; import { AzureAuthentication } from './AzureAuthentication'; @@ -12,6 +12,7 @@ import { AzureSubscriptionProvider } from './AzureSubscriptionProvider'; import { getSessionFromVSCode } from './getSessionFromVSCode'; import { NotSignedInError } from './NotSignedInError'; import { getConfiguredAuthProviderId, getConfiguredAzureEnv } from './utils/configuredAzureEnv'; +import { AzureTenant } from './AzureTenant'; const EventDebounce = 5 * 1000; // 5 seconds @@ -60,9 +61,8 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement * * @returns A list of tenants. */ - public async getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise { - const results: TenantIdDescription[] = []; - + public async getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise { + const results: AzureTenant[] = []; for await (account of account ? [account] : await vscode.authentication.getAccounts(getConfiguredAuthProviderId())) { // Added check. Without this the getSubscriptionClient function throws the NotSignedInError if (await this.isSignedIn(undefined, account)) { @@ -70,7 +70,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement const { client } = await this.getSubscriptionClient(account, undefined, undefined); for await (const tenant of client.tenants.list()) { - results.push(tenant); + results.push({ ...tenant, account }); } } } diff --git a/auth/src/index.ts b/auth/src/index.ts index 823dc6a297..573ae9aca5 100644 --- a/auth/src/index.ts +++ b/auth/src/index.ts @@ -5,6 +5,7 @@ export * from './AzureAuthentication'; export * from './AzureDevOpsSubscriptionProvider'; +export * from './AzureTenant'; export * from './AzureSubscription'; export * from './AzureSubscriptionProvider'; export * from './NotSignedInError'; @@ -12,4 +13,3 @@ export * from './signInToTenant'; export * from './utils/configuredAzureEnv'; export * from './utils/getUnauthenticatedTenants'; export * from './VSCodeAzureSubscriptionProvider'; -