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: Make getSession synchronous #1619

Merged
merged 4 commits into from
Nov 3, 2023
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
45 changes: 3 additions & 42 deletions auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions 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": "1.3.2",
"version": "1.4.0",
"description": "Azure authentication helpers for Visual Studio Code",
"tags": [
"azure",
Expand Down Expand Up @@ -53,7 +53,6 @@
},
"dependencies": {
"@azure/arm-subscriptions": "^5.1.0",
"@azure/ms-rest-azure-env": "^2.0.0",
"node-fetch": "2.6.7"
"@azure/ms-rest-azure-env": "^2.0.0"
}
}
19 changes: 7 additions & 12 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-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 fetch from 'node-fetch'; // have to explicitly use node-fetch v2.6.7 otherwise when @azure/client-core makes a streaming request, it fails on windows
import * as vscode from 'vscode';
import type { AzureAuthentication } from './AzureAuthentication';
import type { AzureSubscription, SubscriptionId, TenantId } from './AzureSubscription';
Expand Down Expand Up @@ -235,21 +234,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): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> {
private async getSubscriptionClient(tenantId?: string, scopes?: string[]): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> {
const armSubs = await import('@azure/arm-subscriptions');

const getSession = async (scopes?: string[] | string): Promise<vscode.AuthenticationSession> => {
const session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true });
if (!session) {
throw new NotSignedInError();
}
return session;
const session = await getSessionFromVSCode(scopes, tenantId, { createIfNone: false, silent: true });
if (!session) {
throw new NotSignedInError();
}

const credential: TokenCredential = {
getToken: async (scopes) => {
getToken: async () => {
return {
token: (await getSession(scopes)).accessToken,
token: session.accessToken,
expiresOnTimestamp: 0
};
}
Expand All @@ -259,7 +254,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
client: new armSubs.SubscriptionClient(credential),
credential: credential,
authentication: {
getSession,
getSession: () => session
}
};
}
Expand Down