// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import * as crypto from 'crypto';
// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "multi-account-test" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable = vscode.commands.registerCommand('multi-account-test.helloWorld', async () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from multi-account-test!');
const accounts = await vscode.authentication.getAccounts('multi-account-test');
console.log('accounts', accounts);
const session = await vscode.authentication.getSession('multi-account-test', ['scope1'], { account: accounts[0] });
console.log('session', session);
});
context.subscriptions.push(disposable);
const account1 = { id: 'test-account-id-1', label: 'Test Account 1' };
const account2 = { id: 'test-account-id-2', label: 'Test Account 2' };
let sessions: vscode.AuthenticationSession[] = [
{
id: 'test-id-' + crypto.randomUUID(),
accessToken: 'test-token-' + crypto.randomUUID(),
account: account1,
scopes: ['scope1'],
},
{
id: 'test-id-' + crypto.randomUUID(),
accessToken: 'test-token-' + crypto.randomUUID(),
account: account1,
scopes: ['scope2'],
},
{
id: 'test-id-' + crypto.randomUUID(),
accessToken: 'test-token-' + crypto.randomUUID(),
account: account2,
scopes: ['scope1'],
},
{
id: 'test-id-' + crypto.randomUUID(),
accessToken: 'test-token-' + crypto.randomUUID(),
account: account2,
scopes: ['scope2'],
},
];
const emitter = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
vscode.authentication.registerAuthenticationProvider('multi-account-test', 'Multi Account Test', {
onDidChangeSessions: emitter.event,
getSessions: async (scopes: readonly string[] | undefined, options: vscode.AuthenticationProviderSessionOptions): Promise<vscode.AuthenticationSession[]> => {
return sessions.slice();
},
createSession: async (scopes: readonly string[], options: vscode.AuthenticationProviderSessionOptions): Promise<vscode.AuthenticationSession> => {
return {
id: 'test-id-' + crypto.randomUUID(),
accessToken: 'test-token-' + crypto.randomUUID(),
account: options.account || { id: 'test-account-id', label: 'Test Account' },
scopes: scopes,
};
},
removeSession: async (sessionId: string): Promise<void> => {
const removed = sessions.filter(session => session.id === sessionId);
sessions = sessions.filter(session => session.id !== sessionId);
emitter.fire({ added: [], removed, changed: [] });
},
}, { supportsMultipleAccounts: true });
}
// This method is called when your extension is deactivated
export function deactivate() {}
Testing #226540
After clicking:
I see:
Where I can't distinguish the sessions. Code: