@codingame/monaco-vscode-authentication-service-override 18.4.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +5 -1
- package/package.json +5 -4
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageAccountPreferencesForExtensionAction.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageAccountPreferencesForExtensionAction.js +171 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageAccountPreferencesForMcpServerAction.d.ts +6 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageAccountPreferencesForMcpServerAction.js +171 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageDynamicAuthenticationProvidersAction.d.ts +7 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageDynamicAuthenticationProvidersAction.js +76 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageTrustedExtensionsForAccountAction.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageTrustedExtensionsForAccountAction.js +177 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageTrustedMcpServersForAccountAction.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/manageTrustedMcpServersForAccountAction.js +171 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/signOutOfAccountAction.d.ts +9 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/actions/signOutOfAccountAction.js +52 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/authentication.contribution.d.ts +1 -0
- package/vscode/src/vs/workbench/contrib/authentication/browser/authentication.contribution.js +140 -0
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationAccessService.js +39 -6
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationExtensionsService.js +9 -9
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationQueryService.d.ts +39 -0
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationQueryService.js +613 -0
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationUsageService.d.ts +1 -0
- package/vscode/src/vs/workbench/services/authentication/browser/authenticationUsageService.js +7 -2
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
|
|
2
|
+
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
|
+
import { Emitter } from '@codingame/monaco-vscode-api/vscode/vs/base/common/event';
|
|
4
|
+
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
5
|
+
import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/extensions';
|
|
6
|
+
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
7
|
+
import { INTERNAL_AUTH_PROVIDER_PREFIX } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/common/authentication';
|
|
8
|
+
import { IAuthenticationService, IAuthenticationExtensionsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/common/authentication.service';
|
|
9
|
+
import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
|
|
10
|
+
import { IAuthenticationUsageService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/browser/authenticationUsageService.service';
|
|
11
|
+
import { IAuthenticationMcpUsageService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/browser/authenticationMcpUsageService.service';
|
|
12
|
+
import { IAuthenticationAccessService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/browser/authenticationAccessService.service';
|
|
13
|
+
import { IAuthenticationMcpAccessService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/browser/authenticationMcpAccessService.service';
|
|
14
|
+
import { IAuthenticationMcpService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/authentication/browser/authenticationMcpService.service';
|
|
15
|
+
import { ExtensionIdentifier } from '@codingame/monaco-vscode-api/vscode/vs/platform/extensions/common/extensions';
|
|
16
|
+
|
|
17
|
+
class BaseQuery {
|
|
18
|
+
constructor(providerId, queryService) {
|
|
19
|
+
this.providerId = providerId;
|
|
20
|
+
this.queryService = queryService;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class AccountExtensionQuery extends BaseQuery {
|
|
24
|
+
constructor(providerId, accountName, extensionId, queryService) {
|
|
25
|
+
super(providerId, queryService);
|
|
26
|
+
this.accountName = accountName;
|
|
27
|
+
this.extensionId = extensionId;
|
|
28
|
+
}
|
|
29
|
+
isAccessAllowed() {
|
|
30
|
+
return this.queryService.authenticationAccessService.isAccessAllowed(this.providerId, this.accountName, this.extensionId);
|
|
31
|
+
}
|
|
32
|
+
setAccessAllowed(allowed, extensionName) {
|
|
33
|
+
this.queryService.authenticationAccessService.updateAllowedExtensions(this.providerId, this.accountName, [{ id: this.extensionId, name: extensionName || this.extensionId, allowed }]);
|
|
34
|
+
}
|
|
35
|
+
addUsage(scopes, extensionName) {
|
|
36
|
+
this.queryService.authenticationUsageService.addAccountUsage(this.providerId, this.accountName, scopes, this.extensionId, extensionName);
|
|
37
|
+
}
|
|
38
|
+
getUsage() {
|
|
39
|
+
const allUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
40
|
+
return ( allUsages
|
|
41
|
+
.filter(usage => usage.extensionId === ExtensionIdentifier.toKey(this.extensionId))
|
|
42
|
+
.map(usage => ({
|
|
43
|
+
extensionId: usage.extensionId,
|
|
44
|
+
extensionName: usage.extensionName,
|
|
45
|
+
scopes: usage.scopes || [],
|
|
46
|
+
lastUsed: usage.lastUsed
|
|
47
|
+
})));
|
|
48
|
+
}
|
|
49
|
+
removeUsage() {
|
|
50
|
+
const allUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
51
|
+
const filteredUsages = allUsages.filter(usage => usage.extensionId !== this.extensionId);
|
|
52
|
+
this.queryService.authenticationUsageService.removeAccountUsage(this.providerId, this.accountName);
|
|
53
|
+
for (const usage of filteredUsages) {
|
|
54
|
+
this.queryService.authenticationUsageService.addAccountUsage(this.providerId, this.accountName, usage.scopes || [], usage.extensionId, usage.extensionName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
setAsPreferred() {
|
|
58
|
+
this.queryService.authenticationExtensionsService.updateAccountPreference(this.extensionId, this.providerId, { label: this.accountName, id: this.accountName });
|
|
59
|
+
}
|
|
60
|
+
isPreferred() {
|
|
61
|
+
const preferredAccount = this.queryService.authenticationExtensionsService.getAccountPreference(this.extensionId, this.providerId);
|
|
62
|
+
return preferredAccount === this.accountName;
|
|
63
|
+
}
|
|
64
|
+
isTrusted() {
|
|
65
|
+
const allowedExtensions = this.queryService.authenticationAccessService.readAllowedExtensions(this.providerId, this.accountName);
|
|
66
|
+
const extension = allowedExtensions.find(ext => ext.id === this.extensionId);
|
|
67
|
+
return extension?.trusted === true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class AccountMcpServerQuery extends BaseQuery {
|
|
71
|
+
constructor(providerId, accountName, mcpServerId, queryService) {
|
|
72
|
+
super(providerId, queryService);
|
|
73
|
+
this.accountName = accountName;
|
|
74
|
+
this.mcpServerId = mcpServerId;
|
|
75
|
+
}
|
|
76
|
+
isAccessAllowed() {
|
|
77
|
+
return this.queryService.authenticationMcpAccessService.isAccessAllowed(this.providerId, this.accountName, this.mcpServerId);
|
|
78
|
+
}
|
|
79
|
+
setAccessAllowed(allowed, mcpServerName) {
|
|
80
|
+
this.queryService.authenticationMcpAccessService.updateAllowedMcpServers(this.providerId, this.accountName, [{ id: this.mcpServerId, name: mcpServerName || this.mcpServerId, allowed }]);
|
|
81
|
+
}
|
|
82
|
+
addUsage(scopes, mcpServerName) {
|
|
83
|
+
this.queryService.authenticationMcpUsageService.addAccountUsage(this.providerId, this.accountName, scopes, this.mcpServerId, mcpServerName);
|
|
84
|
+
}
|
|
85
|
+
getUsage() {
|
|
86
|
+
const allUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
87
|
+
return ( allUsages
|
|
88
|
+
.filter(usage => usage.mcpServerId === this.mcpServerId)
|
|
89
|
+
.map(usage => ({
|
|
90
|
+
mcpServerId: usage.mcpServerId,
|
|
91
|
+
mcpServerName: usage.mcpServerName,
|
|
92
|
+
scopes: usage.scopes || [],
|
|
93
|
+
lastUsed: usage.lastUsed
|
|
94
|
+
})));
|
|
95
|
+
}
|
|
96
|
+
removeUsage() {
|
|
97
|
+
const allUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
98
|
+
const filteredUsages = allUsages.filter(usage => usage.mcpServerId !== this.mcpServerId);
|
|
99
|
+
this.queryService.authenticationMcpUsageService.removeAccountUsage(this.providerId, this.accountName);
|
|
100
|
+
for (const usage of filteredUsages) {
|
|
101
|
+
this.queryService.authenticationMcpUsageService.addAccountUsage(this.providerId, this.accountName, usage.scopes || [], usage.mcpServerId, usage.mcpServerName);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
setAsPreferred() {
|
|
105
|
+
this.queryService.authenticationMcpService.updateAccountPreference(this.mcpServerId, this.providerId, { label: this.accountName, id: this.accountName });
|
|
106
|
+
}
|
|
107
|
+
isPreferred() {
|
|
108
|
+
const preferredAccount = this.queryService.authenticationMcpService.getAccountPreference(this.mcpServerId, this.providerId);
|
|
109
|
+
return preferredAccount === this.accountName;
|
|
110
|
+
}
|
|
111
|
+
isTrusted() {
|
|
112
|
+
const allowedMcpServers = this.queryService.authenticationMcpAccessService.readAllowedMcpServers(this.providerId, this.accountName);
|
|
113
|
+
const mcpServer = allowedMcpServers.find(server => server.id === this.mcpServerId);
|
|
114
|
+
return mcpServer?.trusted === true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class AccountExtensionsQuery extends BaseQuery {
|
|
118
|
+
constructor(providerId, accountName, queryService) {
|
|
119
|
+
super(providerId, queryService);
|
|
120
|
+
this.accountName = accountName;
|
|
121
|
+
}
|
|
122
|
+
getAllowedExtensions() {
|
|
123
|
+
const allowedExtensions = this.queryService.authenticationAccessService.readAllowedExtensions(this.providerId, this.accountName);
|
|
124
|
+
const usages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
125
|
+
return ( allowedExtensions
|
|
126
|
+
.filter(ext => ext.allowed !== false)
|
|
127
|
+
.map(ext => {
|
|
128
|
+
const extensionUsages = usages.filter(usage => usage.extensionId === ext.id);
|
|
129
|
+
const lastUsed = extensionUsages.length > 0 ? Math.max(...( extensionUsages.map(u => u.lastUsed))) : undefined;
|
|
130
|
+
const extensionQuery = ( new AccountExtensionQuery(this.providerId, this.accountName, ext.id, this.queryService));
|
|
131
|
+
const trusted = extensionQuery.isTrusted();
|
|
132
|
+
return {
|
|
133
|
+
id: ext.id,
|
|
134
|
+
name: ext.name,
|
|
135
|
+
allowed: ext.allowed,
|
|
136
|
+
lastUsed,
|
|
137
|
+
trusted
|
|
138
|
+
};
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
allowAccess(extensionIds) {
|
|
142
|
+
const extensionsToAllow = ( extensionIds.map(id => ({ id, name: id, allowed: true })));
|
|
143
|
+
this.queryService.authenticationAccessService.updateAllowedExtensions(this.providerId, this.accountName, extensionsToAllow);
|
|
144
|
+
}
|
|
145
|
+
removeAccess(extensionIds) {
|
|
146
|
+
const extensionsToRemove = ( extensionIds.map(id => ({ id, name: id, allowed: false })));
|
|
147
|
+
this.queryService.authenticationAccessService.updateAllowedExtensions(this.providerId, this.accountName, extensionsToRemove);
|
|
148
|
+
}
|
|
149
|
+
forEach(callback) {
|
|
150
|
+
const usages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
151
|
+
const allowedExtensions = this.queryService.authenticationAccessService.readAllowedExtensions(this.providerId, this.accountName);
|
|
152
|
+
const extensionIds = ( new Set());
|
|
153
|
+
usages.forEach(usage => extensionIds.add(usage.extensionId));
|
|
154
|
+
allowedExtensions.forEach(ext => extensionIds.add(ext.id));
|
|
155
|
+
for (const extensionId of extensionIds) {
|
|
156
|
+
const extensionQuery = ( new AccountExtensionQuery(this.providerId, this.accountName, extensionId, this.queryService));
|
|
157
|
+
callback(extensionQuery);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
class AccountMcpServersQuery extends BaseQuery {
|
|
162
|
+
constructor(providerId, accountName, queryService) {
|
|
163
|
+
super(providerId, queryService);
|
|
164
|
+
this.accountName = accountName;
|
|
165
|
+
}
|
|
166
|
+
getAllowedMcpServers() {
|
|
167
|
+
return this.queryService.authenticationMcpAccessService.readAllowedMcpServers(this.providerId, this.accountName)
|
|
168
|
+
.filter(server => server.allowed !== false);
|
|
169
|
+
}
|
|
170
|
+
allowAccess(mcpServerIds) {
|
|
171
|
+
const mcpServersToAllow = ( mcpServerIds.map(id => ({ id, name: id, allowed: true })));
|
|
172
|
+
this.queryService.authenticationMcpAccessService.updateAllowedMcpServers(this.providerId, this.accountName, mcpServersToAllow);
|
|
173
|
+
}
|
|
174
|
+
removeAccess(mcpServerIds) {
|
|
175
|
+
const mcpServersToRemove = ( mcpServerIds.map(id => ({ id, name: id, allowed: false })));
|
|
176
|
+
this.queryService.authenticationMcpAccessService.updateAllowedMcpServers(this.providerId, this.accountName, mcpServersToRemove);
|
|
177
|
+
}
|
|
178
|
+
forEach(callback) {
|
|
179
|
+
const usages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
180
|
+
const allowedMcpServers = this.queryService.authenticationMcpAccessService.readAllowedMcpServers(this.providerId, this.accountName);
|
|
181
|
+
const mcpServerIds = ( new Set());
|
|
182
|
+
usages.forEach(usage => mcpServerIds.add(usage.mcpServerId));
|
|
183
|
+
allowedMcpServers.forEach(server => mcpServerIds.add(server.id));
|
|
184
|
+
for (const mcpServerId of mcpServerIds) {
|
|
185
|
+
const mcpServerQuery = ( new AccountMcpServerQuery(this.providerId, this.accountName, mcpServerId, this.queryService));
|
|
186
|
+
callback(mcpServerQuery);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
class AccountEntitiesQuery extends BaseQuery {
|
|
191
|
+
constructor(providerId, accountName, queryService) {
|
|
192
|
+
super(providerId, queryService);
|
|
193
|
+
this.accountName = accountName;
|
|
194
|
+
}
|
|
195
|
+
hasAnyUsage() {
|
|
196
|
+
const extensionUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
197
|
+
if (extensionUsages.length > 0) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
const mcpUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
201
|
+
if (mcpUsages.length > 0) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
const allowedExtensions = this.queryService.authenticationAccessService.readAllowedExtensions(this.providerId, this.accountName);
|
|
205
|
+
if (( allowedExtensions.some(ext => ext.allowed !== false))) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const allowedMcpServers = this.queryService.authenticationMcpAccessService.readAllowedMcpServers(this.providerId, this.accountName);
|
|
209
|
+
if (( allowedMcpServers.some(server => server.allowed !== false))) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
getEntityCount() {
|
|
215
|
+
const extensionUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
216
|
+
const allowedExtensions = this.queryService.authenticationAccessService.readAllowedExtensions(this.providerId, this.accountName).filter(ext => ext.allowed);
|
|
217
|
+
const extensionIds = ( new Set());
|
|
218
|
+
extensionUsages.forEach(usage => extensionIds.add(usage.extensionId));
|
|
219
|
+
allowedExtensions.forEach(ext => extensionIds.add(ext.id));
|
|
220
|
+
const mcpUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, this.accountName);
|
|
221
|
+
const allowedMcpServers = this.queryService.authenticationMcpAccessService.readAllowedMcpServers(this.providerId, this.accountName).filter(server => server.allowed);
|
|
222
|
+
const mcpServerIds = ( new Set());
|
|
223
|
+
mcpUsages.forEach(usage => mcpServerIds.add(usage.mcpServerId));
|
|
224
|
+
allowedMcpServers.forEach(server => mcpServerIds.add(server.id));
|
|
225
|
+
const extensionCount = extensionIds.size;
|
|
226
|
+
const mcpServerCount = mcpServerIds.size;
|
|
227
|
+
return {
|
|
228
|
+
extensions: extensionCount,
|
|
229
|
+
mcpServers: mcpServerCount,
|
|
230
|
+
total: extensionCount + mcpServerCount
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
removeAllAccess() {
|
|
234
|
+
const extensionsQuery = ( new AccountExtensionsQuery(this.providerId, this.accountName, this.queryService));
|
|
235
|
+
const extensions = extensionsQuery.getAllowedExtensions();
|
|
236
|
+
const extensionIds = ( extensions.map(ext => ext.id));
|
|
237
|
+
if (extensionIds.length > 0) {
|
|
238
|
+
extensionsQuery.removeAccess(extensionIds);
|
|
239
|
+
}
|
|
240
|
+
const mcpServersQuery = ( new AccountMcpServersQuery(this.providerId, this.accountName, this.queryService));
|
|
241
|
+
const mcpServers = mcpServersQuery.getAllowedMcpServers();
|
|
242
|
+
const mcpServerIds = ( mcpServers.map(server => server.id));
|
|
243
|
+
if (mcpServerIds.length > 0) {
|
|
244
|
+
mcpServersQuery.removeAccess(mcpServerIds);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
forEach(callback) {
|
|
248
|
+
const extensionsQuery = ( new AccountExtensionsQuery(this.providerId, this.accountName, this.queryService));
|
|
249
|
+
extensionsQuery.forEach(extensionQuery => {
|
|
250
|
+
callback(extensionQuery.extensionId, 'extension');
|
|
251
|
+
});
|
|
252
|
+
const mcpServersQuery = ( new AccountMcpServersQuery(this.providerId, this.accountName, this.queryService));
|
|
253
|
+
mcpServersQuery.forEach(mcpServerQuery => {
|
|
254
|
+
callback(mcpServerQuery.mcpServerId, 'mcpServer');
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
class AccountQuery extends BaseQuery {
|
|
259
|
+
constructor(providerId, accountName, queryService) {
|
|
260
|
+
super(providerId, queryService);
|
|
261
|
+
this.accountName = accountName;
|
|
262
|
+
}
|
|
263
|
+
extension(extensionId) {
|
|
264
|
+
return ( new AccountExtensionQuery(this.providerId, this.accountName, extensionId, this.queryService));
|
|
265
|
+
}
|
|
266
|
+
mcpServer(mcpServerId) {
|
|
267
|
+
return ( new AccountMcpServerQuery(this.providerId, this.accountName, mcpServerId, this.queryService));
|
|
268
|
+
}
|
|
269
|
+
extensions() {
|
|
270
|
+
return ( new AccountExtensionsQuery(this.providerId, this.accountName, this.queryService));
|
|
271
|
+
}
|
|
272
|
+
mcpServers() {
|
|
273
|
+
return ( new AccountMcpServersQuery(this.providerId, this.accountName, this.queryService));
|
|
274
|
+
}
|
|
275
|
+
entities() {
|
|
276
|
+
return ( new AccountEntitiesQuery(this.providerId, this.accountName, this.queryService));
|
|
277
|
+
}
|
|
278
|
+
remove() {
|
|
279
|
+
this.queryService.authenticationAccessService.removeAllowedExtensions(this.providerId, this.accountName);
|
|
280
|
+
this.queryService.authenticationUsageService.removeAccountUsage(this.providerId, this.accountName);
|
|
281
|
+
this.queryService.authenticationMcpAccessService.removeAllowedMcpServers(this.providerId, this.accountName);
|
|
282
|
+
this.queryService.authenticationMcpUsageService.removeAccountUsage(this.providerId, this.accountName);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
class ProviderExtensionQuery extends BaseQuery {
|
|
286
|
+
constructor(providerId, extensionId, queryService) {
|
|
287
|
+
super(providerId, queryService);
|
|
288
|
+
this.extensionId = extensionId;
|
|
289
|
+
}
|
|
290
|
+
getPreferredAccount() {
|
|
291
|
+
return this.queryService.authenticationExtensionsService.getAccountPreference(this.extensionId, this.providerId);
|
|
292
|
+
}
|
|
293
|
+
setPreferredAccount(account) {
|
|
294
|
+
this.queryService.authenticationExtensionsService.updateAccountPreference(this.extensionId, this.providerId, account);
|
|
295
|
+
}
|
|
296
|
+
removeAccountPreference() {
|
|
297
|
+
this.queryService.authenticationExtensionsService.removeAccountPreference(this.extensionId, this.providerId);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
class ProviderMcpServerQuery extends BaseQuery {
|
|
301
|
+
constructor(providerId, mcpServerId, queryService) {
|
|
302
|
+
super(providerId, queryService);
|
|
303
|
+
this.mcpServerId = mcpServerId;
|
|
304
|
+
}
|
|
305
|
+
async getLastUsedAccount() {
|
|
306
|
+
try {
|
|
307
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
308
|
+
let lastUsedAccount;
|
|
309
|
+
let lastUsedTime = 0;
|
|
310
|
+
for (const account of accounts) {
|
|
311
|
+
const usages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, account.label);
|
|
312
|
+
const mcpServerUsages = usages.filter(usage => usage.mcpServerId === this.mcpServerId);
|
|
313
|
+
for (const usage of mcpServerUsages) {
|
|
314
|
+
if (usage.lastUsed > lastUsedTime) {
|
|
315
|
+
lastUsedTime = usage.lastUsed;
|
|
316
|
+
lastUsedAccount = account.label;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return lastUsedAccount;
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
getPreferredAccount() {
|
|
327
|
+
return this.queryService.authenticationMcpService.getAccountPreference(this.mcpServerId, this.providerId);
|
|
328
|
+
}
|
|
329
|
+
setPreferredAccount(account) {
|
|
330
|
+
this.queryService.authenticationMcpService.updateAccountPreference(this.mcpServerId, this.providerId, account);
|
|
331
|
+
}
|
|
332
|
+
removeAccountPreference() {
|
|
333
|
+
this.queryService.authenticationMcpService.removeAccountPreference(this.mcpServerId, this.providerId);
|
|
334
|
+
}
|
|
335
|
+
async getUsedAccounts() {
|
|
336
|
+
try {
|
|
337
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
338
|
+
const usedAccounts = [];
|
|
339
|
+
for (const account of accounts) {
|
|
340
|
+
const usages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, account.label);
|
|
341
|
+
if (( usages.some(usage => usage.mcpServerId === this.mcpServerId))) {
|
|
342
|
+
usedAccounts.push(account.label);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return usedAccounts;
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
return [];
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
class ProviderQuery extends BaseQuery {
|
|
353
|
+
constructor(providerId, queryService) {
|
|
354
|
+
super(providerId, queryService);
|
|
355
|
+
}
|
|
356
|
+
account(accountName) {
|
|
357
|
+
return ( new AccountQuery(this.providerId, accountName, this.queryService));
|
|
358
|
+
}
|
|
359
|
+
extension(extensionId) {
|
|
360
|
+
return ( new ProviderExtensionQuery(this.providerId, extensionId, this.queryService));
|
|
361
|
+
}
|
|
362
|
+
mcpServer(mcpServerId) {
|
|
363
|
+
return ( new ProviderMcpServerQuery(this.providerId, mcpServerId, this.queryService));
|
|
364
|
+
}
|
|
365
|
+
async getActiveEntities() {
|
|
366
|
+
const extensions = [];
|
|
367
|
+
const mcpServers = [];
|
|
368
|
+
try {
|
|
369
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
370
|
+
for (const account of accounts) {
|
|
371
|
+
const extensionUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, account.label);
|
|
372
|
+
for (const usage of extensionUsages) {
|
|
373
|
+
if (!extensions.includes(usage.extensionId)) {
|
|
374
|
+
extensions.push(usage.extensionId);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const mcpUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, account.label);
|
|
378
|
+
for (const usage of mcpUsages) {
|
|
379
|
+
if (!mcpServers.includes(usage.mcpServerId)) {
|
|
380
|
+
mcpServers.push(usage.mcpServerId);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
}
|
|
387
|
+
return { extensions, mcpServers };
|
|
388
|
+
}
|
|
389
|
+
async getAccountNames() {
|
|
390
|
+
try {
|
|
391
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
392
|
+
return ( accounts.map(account => account.label));
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
return [];
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
async getUsageStats() {
|
|
399
|
+
const recentActivity = [];
|
|
400
|
+
let totalSessions = 0;
|
|
401
|
+
let totalAccounts = 0;
|
|
402
|
+
try {
|
|
403
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
404
|
+
totalAccounts = accounts.length;
|
|
405
|
+
for (const account of accounts) {
|
|
406
|
+
const extensionUsages = this.queryService.authenticationUsageService.readAccountUsages(this.providerId, account.label);
|
|
407
|
+
const mcpUsages = this.queryService.authenticationMcpUsageService.readAccountUsages(this.providerId, account.label);
|
|
408
|
+
const allUsages = [...extensionUsages, ...mcpUsages];
|
|
409
|
+
const usageCount = allUsages.length;
|
|
410
|
+
const lastUsed = Math.max(...( allUsages.map(u => u.lastUsed)), 0);
|
|
411
|
+
if (usageCount > 0) {
|
|
412
|
+
recentActivity.push({ accountName: account.label, lastUsed, usageCount });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
recentActivity.sort((a, b) => b.lastUsed - a.lastUsed);
|
|
416
|
+
totalSessions = recentActivity.reduce((sum, activity) => sum + activity.usageCount, 0);
|
|
417
|
+
}
|
|
418
|
+
catch {
|
|
419
|
+
}
|
|
420
|
+
return { totalSessions, totalAccounts, recentActivity };
|
|
421
|
+
}
|
|
422
|
+
async forEachAccount(callback) {
|
|
423
|
+
try {
|
|
424
|
+
const accounts = await this.queryService.authenticationService.getAccounts(this.providerId);
|
|
425
|
+
for (const account of accounts) {
|
|
426
|
+
const accountQuery = ( new AccountQuery(this.providerId, account.label, this.queryService));
|
|
427
|
+
callback(accountQuery);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
catch {
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
class ExtensionQuery {
|
|
435
|
+
constructor(extensionId, queryService) {
|
|
436
|
+
this.extensionId = extensionId;
|
|
437
|
+
this.queryService = queryService;
|
|
438
|
+
}
|
|
439
|
+
async getProvidersWithAccess(includeInternal) {
|
|
440
|
+
const providersWithAccess = [];
|
|
441
|
+
const providerIds = this.queryService.authenticationService.getProviderIds();
|
|
442
|
+
for (const providerId of providerIds) {
|
|
443
|
+
if (!includeInternal && providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX)) {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
const accounts = await this.queryService.authenticationService.getAccounts(providerId);
|
|
448
|
+
const hasAccess = ( accounts.some(account => {
|
|
449
|
+
const accessAllowed = this.queryService.authenticationAccessService.isAccessAllowed(providerId, account.label, this.extensionId);
|
|
450
|
+
return accessAllowed === true;
|
|
451
|
+
}));
|
|
452
|
+
if (hasAccess) {
|
|
453
|
+
providersWithAccess.push(providerId);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
catch {
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return providersWithAccess;
|
|
460
|
+
}
|
|
461
|
+
getAllAccountPreferences(includeInternal) {
|
|
462
|
+
const preferences = ( new Map());
|
|
463
|
+
const providerIds = this.queryService.authenticationService.getProviderIds();
|
|
464
|
+
for (const providerId of providerIds) {
|
|
465
|
+
if (!includeInternal && providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX)) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
const preferredAccount = this.queryService.authenticationExtensionsService.getAccountPreference(this.extensionId, providerId);
|
|
469
|
+
if (preferredAccount) {
|
|
470
|
+
preferences.set(providerId, preferredAccount);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return preferences;
|
|
474
|
+
}
|
|
475
|
+
provider(providerId) {
|
|
476
|
+
return ( new ProviderExtensionQuery(providerId, this.extensionId, this.queryService));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
class McpServerQuery {
|
|
480
|
+
constructor(mcpServerId, queryService) {
|
|
481
|
+
this.mcpServerId = mcpServerId;
|
|
482
|
+
this.queryService = queryService;
|
|
483
|
+
}
|
|
484
|
+
async getProvidersWithAccess(includeInternal) {
|
|
485
|
+
const providersWithAccess = [];
|
|
486
|
+
const providerIds = this.queryService.authenticationService.getProviderIds();
|
|
487
|
+
for (const providerId of providerIds) {
|
|
488
|
+
if (!includeInternal && providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX)) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
try {
|
|
492
|
+
const accounts = await this.queryService.authenticationService.getAccounts(providerId);
|
|
493
|
+
const hasAccess = ( accounts.some(account => {
|
|
494
|
+
const accessAllowed = this.queryService.authenticationMcpAccessService.isAccessAllowed(providerId, account.label, this.mcpServerId);
|
|
495
|
+
return accessAllowed === true;
|
|
496
|
+
}));
|
|
497
|
+
if (hasAccess) {
|
|
498
|
+
providersWithAccess.push(providerId);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return providersWithAccess;
|
|
505
|
+
}
|
|
506
|
+
getAllAccountPreferences(includeInternal) {
|
|
507
|
+
const preferences = ( new Map());
|
|
508
|
+
const providerIds = this.queryService.authenticationService.getProviderIds();
|
|
509
|
+
for (const providerId of providerIds) {
|
|
510
|
+
if (!includeInternal && providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX)) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
const preferredAccount = this.queryService.authenticationMcpService.getAccountPreference(this.mcpServerId, providerId);
|
|
514
|
+
if (preferredAccount) {
|
|
515
|
+
preferences.set(providerId, preferredAccount);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
return preferences;
|
|
519
|
+
}
|
|
520
|
+
provider(providerId) {
|
|
521
|
+
return ( new ProviderMcpServerQuery(providerId, this.mcpServerId, this.queryService));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
let AuthenticationQueryService = class AuthenticationQueryService extends Disposable {
|
|
525
|
+
constructor(authenticationService, authenticationUsageService, authenticationMcpUsageService, authenticationAccessService, authenticationMcpAccessService, authenticationExtensionsService, authenticationMcpService, logService) {
|
|
526
|
+
super();
|
|
527
|
+
this.authenticationService = authenticationService;
|
|
528
|
+
this.authenticationUsageService = authenticationUsageService;
|
|
529
|
+
this.authenticationMcpUsageService = authenticationMcpUsageService;
|
|
530
|
+
this.authenticationAccessService = authenticationAccessService;
|
|
531
|
+
this.authenticationMcpAccessService = authenticationMcpAccessService;
|
|
532
|
+
this.authenticationExtensionsService = authenticationExtensionsService;
|
|
533
|
+
this.authenticationMcpService = authenticationMcpService;
|
|
534
|
+
this.logService = logService;
|
|
535
|
+
this._onDidChangePreferences = this._register(( new Emitter()));
|
|
536
|
+
this.onDidChangePreferences = this._onDidChangePreferences.event;
|
|
537
|
+
this._onDidChangeAccess = this._register(( new Emitter()));
|
|
538
|
+
this.onDidChangeAccess = this._onDidChangeAccess.event;
|
|
539
|
+
this._register(this.authenticationExtensionsService.onDidChangeAccountPreference(e => {
|
|
540
|
+
this._onDidChangePreferences.fire({
|
|
541
|
+
providerId: e.providerId,
|
|
542
|
+
entityType: 'extension',
|
|
543
|
+
entityIds: e.extensionIds
|
|
544
|
+
});
|
|
545
|
+
}));
|
|
546
|
+
this._register(this.authenticationMcpService.onDidChangeAccountPreference(e => {
|
|
547
|
+
this._onDidChangePreferences.fire({
|
|
548
|
+
providerId: e.providerId,
|
|
549
|
+
entityType: 'mcpServer',
|
|
550
|
+
entityIds: e.mcpServerIds
|
|
551
|
+
});
|
|
552
|
+
}));
|
|
553
|
+
this._register(this.authenticationAccessService.onDidChangeExtensionSessionAccess(e => {
|
|
554
|
+
this._onDidChangeAccess.fire({
|
|
555
|
+
providerId: e.providerId,
|
|
556
|
+
accountName: e.accountName
|
|
557
|
+
});
|
|
558
|
+
}));
|
|
559
|
+
this._register(this.authenticationMcpAccessService.onDidChangeMcpSessionAccess(e => {
|
|
560
|
+
this._onDidChangeAccess.fire({
|
|
561
|
+
providerId: e.providerId,
|
|
562
|
+
accountName: e.accountName
|
|
563
|
+
});
|
|
564
|
+
}));
|
|
565
|
+
}
|
|
566
|
+
provider(providerId) {
|
|
567
|
+
return ( new ProviderQuery(providerId, this));
|
|
568
|
+
}
|
|
569
|
+
extension(extensionId) {
|
|
570
|
+
return ( new ExtensionQuery(extensionId, this));
|
|
571
|
+
}
|
|
572
|
+
mcpServer(mcpServerId) {
|
|
573
|
+
return ( new McpServerQuery(mcpServerId, this));
|
|
574
|
+
}
|
|
575
|
+
getProviderIds(includeInternal) {
|
|
576
|
+
return this.authenticationService.getProviderIds().filter(providerId => {
|
|
577
|
+
return includeInternal || !providerId.startsWith(INTERNAL_AUTH_PROVIDER_PREFIX);
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
async clearAllData(confirmation, includeInternal = true) {
|
|
581
|
+
if (confirmation !== 'CLEAR_ALL_AUTH_DATA') {
|
|
582
|
+
throw ( new Error('Must provide confirmation string to clear all authentication data'));
|
|
583
|
+
}
|
|
584
|
+
const providerIds = this.getProviderIds(includeInternal);
|
|
585
|
+
for (const providerId of providerIds) {
|
|
586
|
+
try {
|
|
587
|
+
const accounts = await this.authenticationService.getAccounts(providerId);
|
|
588
|
+
for (const account of accounts) {
|
|
589
|
+
this.authenticationAccessService.removeAllowedExtensions(providerId, account.label);
|
|
590
|
+
this.authenticationUsageService.removeAccountUsage(providerId, account.label);
|
|
591
|
+
this.authenticationMcpAccessService.removeAllowedMcpServers(providerId, account.label);
|
|
592
|
+
this.authenticationMcpUsageService.removeAccountUsage(providerId, account.label);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
this.logService.error(`Error clearing data for provider ${providerId}:`, error);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
this.logService.info('All authentication data cleared');
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
AuthenticationQueryService = ( __decorate([
|
|
603
|
+
( __param(0, IAuthenticationService)),
|
|
604
|
+
( __param(1, IAuthenticationUsageService)),
|
|
605
|
+
( __param(2, IAuthenticationMcpUsageService)),
|
|
606
|
+
( __param(3, IAuthenticationAccessService)),
|
|
607
|
+
( __param(4, IAuthenticationMcpAccessService)),
|
|
608
|
+
( __param(5, IAuthenticationExtensionsService)),
|
|
609
|
+
( __param(6, IAuthenticationMcpService)),
|
|
610
|
+
( __param(7, ILogService))
|
|
611
|
+
], AuthenticationQueryService));
|
|
612
|
+
|
|
613
|
+
export { AuthenticationQueryService };
|
package/vscode/src/vs/workbench/services/authentication/browser/authenticationUsageService.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class AuthenticationUsageService extends Disposable implements IA
|
|
|
17
17
|
_serviceBrand: undefined;
|
|
18
18
|
private _queue;
|
|
19
19
|
private _extensionsUsingAuth;
|
|
20
|
+
private _disposed;
|
|
20
21
|
constructor(_storageService: IStorageService, _authenticationService: IAuthenticationService, _logService: ILogService, productService: IProductService);
|
|
21
22
|
initializeExtensionUsageCache(): Promise<void>;
|
|
22
23
|
extensionUsesAuth(extensionId: string): Promise<boolean>;
|
package/vscode/src/vs/workbench/services/authentication/browser/authenticationUsageService.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { __decorate, __param } from '@codingame/monaco-vscode-api/external/tslib/tslib.es6';
|
|
3
3
|
import { Queue } from '@codingame/monaco-vscode-api/vscode/vs/base/common/async';
|
|
4
|
-
import { Disposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
4
|
+
import { Disposable, toDisposable } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
|
|
5
5
|
import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/extensions';
|
|
6
6
|
import { ILogService } from '@codingame/monaco-vscode-api/vscode/vs/platform/log/common/log.service';
|
|
7
7
|
import { IProductService } from '@codingame/monaco-vscode-api/vscode/vs/platform/product/common/productService.service';
|
|
@@ -16,8 +16,10 @@ let AuthenticationUsageService = class AuthenticationUsageService extends Dispos
|
|
|
16
16
|
this._storageService = _storageService;
|
|
17
17
|
this._authenticationService = _authenticationService;
|
|
18
18
|
this._logService = _logService;
|
|
19
|
-
this._queue = ( new Queue());
|
|
19
|
+
this._queue = this._register(( new Queue()));
|
|
20
20
|
this._extensionsUsingAuth = ( new Set());
|
|
21
|
+
this._disposed = false;
|
|
22
|
+
this._register(toDisposable(() => this._disposed = true));
|
|
21
23
|
const trustedExtensionAuthAccess = productService.trustedExtensionAuthAccess;
|
|
22
24
|
if (Array.isArray(trustedExtensionAuthAccess)) {
|
|
23
25
|
for (const extensionId of trustedExtensionAuthAccess) {
|
|
@@ -81,6 +83,9 @@ let AuthenticationUsageService = class AuthenticationUsageService extends Dispos
|
|
|
81
83
|
this._extensionsUsingAuth.add(extensionId);
|
|
82
84
|
}
|
|
83
85
|
async _addExtensionsToCache(providerId) {
|
|
86
|
+
if (this._disposed) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
84
89
|
try {
|
|
85
90
|
const accounts = await this._authenticationService.getAccounts(providerId);
|
|
86
91
|
for (const account of accounts) {
|