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

Revert "auth: Allow getting access token with custom scope" #1642

Merged
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": "2.0.1",
"version": "2.0.0",
"description": "Azure authentication helpers for Visual Studio Code",
"tags": [
"azure",
Expand Down
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