diff --git a/auth/src/VSCodeAzureSubscriptionProvider.ts b/auth/src/VSCodeAzureSubscriptionProvider.ts index 6ec7108b1e..8ccb775a56 100644 --- a/auth/src/VSCodeAzureSubscriptionProvider.ts +++ b/auth/src/VSCodeAzureSubscriptionProvider.ts @@ -237,37 +237,30 @@ 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): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> { - const initialSession = await getSessionFromVSCode(undefined, tenantId, { createIfNone: false, silent: true }); - if (!initialSession) { + private async getSubscriptionClient(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 }); + if (!session) { throw new NotSignedInError(); } const credential: TokenCredential = { - getToken: async (scopes, _options) => { - const session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true }); - if (session?.accessToken) { - return { - token: session.accessToken, - expiresOnTimestamp: 0 - }; - } else { - return null; - } + getToken: async () => { + return { + token: session.accessToken, + expiresOnTimestamp: 0 + }; } } const configuredAzureEnv = getConfiguredAzureEnv(); const endpoint = configuredAzureEnv.resourceManagerEndpointUrl; - const armSubs = await import('@azure/arm-resources-subscriptions'); return { client: new armSubs.SubscriptionClient(credential, { endpoint }), credential: credential, authentication: { - getSession: async (scopes) => { - return await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true }); - } + getSession: () => session } }; }