测试 #226540
请求 'scope2' 和账户 2,我得到了 'scope1' 和账户 1:
扩展程序可以访问账户 1,但不能访问账户 2。我期望返回 undefined
并允许用户界面让我授予扩展程序访问账户 2 的权限。
代码:
// 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', ['scope2'], { account: accounts[1] });
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'],
},
{
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() {}
2条答案
按热度按时间e0bqpujr1#
createIfNone: true
后,选择器显示了同一帐户的多个条目(Cannot distinguish sessions in picker #226781)。帐户没有按scope2
进行过滤(作为传递给getSession
的参数),这似乎是个bug。createIfNone: true
重新运行时,它再次询问我是否允许扩展程序登录,但然后没有显示选择器,而是只返回了我之前的选择。它可能不应该在第二次询问我是否允许扩展程序登录。z9gpfhce2#
$x_1m_0n_1^x$ 实现了,但是它工作得并不像我想象的那样。$x_1m_1n_1^x$ 应该显示会话选择器吗?我没有看到那个。
$x_1a_b^x$