Change:
<ins> /*--------------------------------------------------------------------------------------------- *  Copyright (c) Microsoft Corporation. All rights reserved. *  Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; import { AuthenticationProviderInformation } from 'vs/editor/common/modes'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { TestDialogService } from 'vs/platform/dialogs/test/common/testDialogService'; import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService'; import { IQuickInputHideEvent, IQuickInputService, IQuickPickDidAcceptEvent } from 'vs/platform/quickinput/common/quickInput'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { MainThreadAuthentication } from 'vs/workbench/api/browser/mainThreadAuthentication'; import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol'; import { IActivityService } from 'vs/workbench/services/activity/common/activity'; import { AuthenticationService, IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService'; import { ExtensionHostKind, IExtensionService } from 'vs/workbench/services/extensions/common/extensions'; import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService'; import { TestRemoteAgentService } from 'vs/workbench/services/remote/test/common/testServices'; import { TestQuickInputService } from 'vs/workbench/test/browser/workbenchTestServices'; import { TestActivityService, TestExtensionService, TestStorageService } from 'vs/workbench/test/common/workbenchTestServices'; function createSession(id: string = '1234', scope: string[] = []) { return { accessToken: '1234', account: { id: 'test@test.com', label: 'Test Person' }, id: id, scopes: scope }; } class AuthQuickPick { private listener: ((e: IQuickPickDidAcceptEvent) => any) | undefined; public items = []; public get selectedItems(): string[] { return this.items; } onDidAccept(listener: (e: IQuickPickDidAcceptEvent) => any) { this.listener = listener; } onDidHide(listener: (e: IQuickInputHideEvent) => any) { } dispose() { } show() { this.listener!({ inBackground: false }); } } class AuthTestQuickInputService extends TestQuickInputService { override createQuickPick() { return <any>new AuthQuickPick(); } } suite('MainThreadAuthentication', () => { let mainThreadAuthentication: MainThreadAuthentication; suiteSetup(async () => { // extHostContext: IExtHostContext, const services = new ServiceCollection(); const dialogService = new TestDialogService(); const storageService = new TestStorageService(); const quickInputService = new AuthTestQuickInputService(); const extensionService = new TestExtensionService(); const activityService = new TestActivityService(); const remoteAgentService = new TestRemoteAgentService(); services.set(IDialogService, dialogService); services.set(IStorageService, storageService); services.set(INotificationService, new TestNotificationService()); services.set(IQuickInputService, quickInputService); services.set(IExtensionService, extensionService); services.set(IActivityService, activityService); services.set(IRemoteAgentService, remoteAgentService); const instaService = new InstantiationService(services); services.set(IAuthenticationService, instaService.createInstance(AuthenticationService)); mainThreadAuthentication = instaService.createInstance(MainThreadAuthentication, new class implements IExtHostContext { remoteAuthority = ''; extensionHostKind = ExtensionHostKind.LocalProcess; assertRegistered() { } set(v: any): any { return null; } getProxy(): any { return { $getSessions(id: string, scopes: string[]) { return Promise.resolve([createSession(id, scopes)]); }, $createSession(id: string, scopes: string[]) { return Promise.resolve(createSession(id, scopes)); }, $removeSession(id: string, sessionId: string) { return Promise.resolve(); }, $onDidChangeAuthenticationSessions(id: string, label: string) { return Promise.resolve(); }, $onDidChangeAuthenticationProviders(added: AuthenticationProviderInformation[], removed: AuthenticationProviderInformation[]) { return Promise.resolve(); }, $setProviders(providers: AuthenticationProviderInformation[]) { return Promise.resolve(); } }; } drain(): any { return null; } }); await mainThreadAuthentication.$registerAuthenticationProvider('test', 'test provider', true); }); suiteTeardown(() => { mainThreadAuthentication.$unregisterAuthenticationProvider('test'); }); test('Can get a session', async () => { const session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'foo'); }); test('Can get multiple sessions (with different scopes) in one extension', async () => { let session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); session = await mainThreadAuthentication.$getSession('test', ['bar'], 'testextension', 'test extension', { createIfNone: true, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'bar'); session = await mainThreadAuthentication.$getSession('test', ['foo'], 'testextension', 'test extension', { createIfNone: false, clearSessionPreference: false }); assert.strictEqual(session?.id, 'test'); assert.strictEqual(session?.scopes[0], 'foo'); }); }); </ins>

Discussion:
<!-- Do Not Delete This! bugreporttemplate --<!-- Please read our Rules of Conduct: --<!-- Read our guide about submitting issues: --<!-- Search existing issues to avoid creating duplicates. --<!-- Test using the latest Insiders build to see if your issue has already been fixed: --<!-- Instead of creating your report here, use 'Report Issue' from the 'Help' menu in VS Code to pre-fill useful information. --<!-- Launch with to check. --Does this issue occur when all extensions are disabled?: Yes/No <!-- If you answered No above, use 'Help: Start Extension Bisect' from Command Palette to try to identify the cause. --<!-- Issues caused by an extension need to be reported directly to the extension publisher. The 'Help Report Issue' dialog can assist with this. --- VS Code Version: OS Version: Steps to Reproduce: an extension that does this: 'll notice that is though it should exist because we created it on line 1. This is because we cache the session id based on the provider id & extension name but really we should be caching them based on provider id, extension name, AND SCOPES. This will allow the 3rd time to find the session created in the first line.
Verification steps: The code session3 should not be undefined.
is your solution to this issue the reason that the Insiders builds have started bugging me at least once a day to sign into GitHub? With four windows open, each with two extensions that want a GitHub token (GitLens and GitHub Issues and Pull Requests), I have to generate 8 tokens to make VS Code stop bugging me... at which point it almost always discovers a VS Code update, and often we do the dance again after it restarts.
(And never mind, I see it was, and I see you fixed it!)
Reopening this because I reverted the change that fixed it.
just checking to see if there were any updates on this issue?
haven't had a chance to revisit this. You can take a look at my commit if you'd like. The problem I needed to address is migrating from the old storage keys to the new storage keys and my commit didn't handle that. Unfortunately, I have some other work I'm working on at the moment so I won't be able to look at this this month.
This appears to be fixed. Closing now
verification: original steps to repro. Instead, session3 should be defined.