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: Add changes to be compatible with the new tenant view #1789

Merged
merged 10 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
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
30 changes: 14 additions & 16 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
* @returns A list of tenants.
*/
public async getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<TenantIdDescription[]> {
alexweininger marked this conversation as resolved.
Show resolved Hide resolved
const session = await getSessionFromVSCode(undefined, undefined, { account });
const { client } = await this.getSubscriptionClient(undefined, undefined, session);

const results: TenantIdDescription[] = [];
const accounts = account ? [account] : await vscode.authentication.getAccounts(getConfiguredAuthProviderId());

for (account of accounts) {
alexweininger marked this conversation as resolved.
Show resolved Hide resolved
const { client } = await this.getSubscriptionClient(account, undefined, undefined);

for await (const tenant of client.tenants.list()) {
results.push(tenant);
for await (const tenant of client.tenants.list()) {
results.push(tenant);
}
}

return results;
Expand Down Expand Up @@ -212,7 +214,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
* @returns The list of subscriptions for the tenant.
*/
private async getSubscriptionsForTenant(tenantId: string, account: vscode.AuthenticationSessionAccountInformation): Promise<AzureSubscription[]> {
const { client, credential, authentication } = await this.getSubscriptionClient(tenantId, undefined, undefined, account);
const { client, credential, authentication } = await this.getSubscriptionClient(account, tenantId, undefined);
const environment = getConfiguredAzureEnv();

const subscriptions: AzureSubscription[] = [];
Expand Down Expand Up @@ -242,21 +244,17 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
*
* @returns A client, the credential used by the client, and the authentication function
*/
private async getSubscriptionClient(tenantId?: string, scopes?: string[], session?: vscode.AuthenticationSession, account?: vscode.AuthenticationSessionAccountInformation): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> {
private async getSubscriptionClient(account: vscode.AuthenticationSessionAccountInformation, tenantId?: string, scopes?: string[]): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> {
const armSubs = await import('@azure/arm-resources-subscriptions');

const session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true, account });

if (!session) {
if (account) {
session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true, account });
} else {
session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true });
}
throw new NotSignedInError();
}

const credential: TokenCredential = {
getToken: async () => {
if (!session) {
throw new NotSignedInError();
}
return {
token: session.accessToken,
expiresOnTimestamp: 0
Expand All @@ -273,7 +271,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
authentication: {
getSession: () => session,
getSessionWithScopes: (scopes) => {
return getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true })
return getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true, account });
},
}
};
Expand Down
Loading