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 authentication.getSession use scopes argument #1597

Merged
merged 1 commit into from
Sep 21, 2023
Merged
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
19 changes: 9 additions & 10 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,18 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
private async getSubscriptionClient(tenantId?: string): Promise<{ client: SubscriptionClient, credential: TokenCredential, authentication: AzureAuthentication }> {
const armSubs = await import('@azure/arm-subscriptions');

// This gets filled in when the client calls `getToken`, and then it can be returned in the `authentication` property of `AzureSubscription`
let session: vscode.AuthenticationSession | undefined;
const getSession = async (scopes?: string[]): Promise<vscode.AuthenticationSession> => {
const session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getScopes(scopes, tenantId), { createIfNone: false, silent: true });
if (!session) {
throw new NotSignedInError();
}
return session;
}

const credential: TokenCredential = {
getToken: async (scopes) => {
// TODO: if possible, change to `getSessions` when that API is available: https://github.com/microsoft/vscode/issues/152399
session = await vscode.authentication.getSession(getConfiguredAuthProviderId(), this.getScopes(scopes, tenantId), { createIfNone: false, silent: true });
if (!session) {
throw new NotSignedInError();
}

return {
token: session.accessToken,
token: (await getSession(this.getScopes(scopes, tenantId))).accessToken,
expiresOnTimestamp: 0
};
}
Expand All @@ -259,7 +258,7 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
client: new armSubs.SubscriptionClient(credential),
credential: credential,
authentication: {
getSession: () => session // Rewrapped to make TS not confused about the weird initialization pattern
getSession
}
};
}
Expand Down