Skip to content

Commit

Permalink
Revert "Allow getting session and access token with custom scope (#1643
Browse files Browse the repository at this point in the history
…)"

This reverts commit 6d3f494.
  • Loading branch information
alexweininger committed Dec 14, 2023
1 parent 8984f78 commit ab599f7
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
}
Expand Down

0 comments on commit ab599f7

Please sign in to comment.