@codingame/monaco-vscode-authentication-service-override 4.0.0 → 4.1.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/authentication.js CHANGED
@@ -3,7 +3,7 @@ import { IAuthenticationService, IAuthenticationExtensionsService } from 'vscode
3
3
  import { AuthenticationService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationService';
4
4
  import { IAuthenticationAccessService, AuthenticationAccessService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationAccessService';
5
5
  import { IAuthenticationUsageService, AuthenticationUsageService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationUsageService';
6
- import { AuthenticationExtensionsService } from './vscode/src/vs/workbench/services/authentication/browser/authenticationExtensionsService.js';
6
+ import { AuthenticationExtensionsService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationExtensionsService';
7
7
 
8
8
  function getServiceOverride() {
9
9
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-authentication-service-override",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "keywords": [],
5
5
  "author": {
6
6
  "name": "CodinGame",
@@ -18,6 +18,6 @@
18
18
  "module": "index.js",
19
19
  "types": "index.d.ts",
20
20
  "dependencies": {
21
- "vscode": "npm:@codingame/monaco-vscode-api@4.0.0"
21
+ "vscode": "npm:@codingame/monaco-vscode-api@4.1.0"
22
22
  }
23
23
  }
@@ -1,11 +0,0 @@
1
- function __decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- }
7
- function __param(paramIndex, decorator) {
8
- return function (target, key) { decorator(target, key, paramIndex); }
9
- }
10
-
11
- export { __decorate, __param };
@@ -1,10 +0,0 @@
1
- export { AbstractDialogHandler, IDialogService, IFileDialogService, getFileNamesMessage } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
2
-
3
- var ConfirmResult;
4
- ( (function(ConfirmResult) {
5
- ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
6
- ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
7
- ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
8
- })(ConfirmResult || (ConfirmResult = {})));
9
-
10
- export { ConfirmResult };
@@ -1,371 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
- import { Disposable, MutableDisposable, dispose } from 'vscode/vscode/vs/base/common/lifecycle';
3
- import { localizeWithPath } from 'vscode/vscode/vs/nls';
4
- import { MenuRegistry, MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
5
- import { CommandsRegistry } from 'vscode/vscode/vs/platform/commands/common/commands';
6
- import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
7
- import { Severity } from 'vscode/vscode/vs/platform/notification/common/notification';
8
- import { IQuickInputService } from 'vscode/vscode/vs/platform/quickinput/common/quickInput';
9
- import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
10
- import { NumberBadge, IActivityService } from 'vscode/vscode/vs/workbench/services/activity/common/activity';
11
- import { IAuthenticationAccessService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationAccessService';
12
- import { IAuthenticationUsageService } from 'vscode/vscode/vs/workbench/services/authentication/browser/authenticationUsageService';
13
- import { IAuthenticationService } from 'vscode/vscode/vs/workbench/services/authentication/common/authentication';
14
- import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
15
-
16
- const SCOPESLIST_SEPARATOR = ' ';
17
- let AuthenticationExtensionsService = class AuthenticationExtensionsService extends Disposable {
18
- constructor(activityService, storageService, dialogService, quickInputService, _authenticationService, _authenticationUsageService, _authenticationAccessService) {
19
- super();
20
- this.activityService = activityService;
21
- this.storageService = storageService;
22
- this.dialogService = dialogService;
23
- this.quickInputService = quickInputService;
24
- this._authenticationService = _authenticationService;
25
- this._authenticationUsageService = _authenticationUsageService;
26
- this._authenticationAccessService = _authenticationAccessService;
27
- this._signInRequestItems = ( new Map());
28
- this._sessionAccessRequestItems = ( new Map());
29
- this._accountBadgeDisposable = this._register(( new MutableDisposable()));
30
- this.registerListeners();
31
- }
32
- registerListeners() {
33
- this._register(this._authenticationService.onDidChangeSessions(async (e) => {
34
- if (e.event.added?.length) {
35
- await this.updateNewSessionRequests(e.providerId, e.event.added);
36
- }
37
- if (e.event.removed?.length) {
38
- await this.updateAccessRequests(e.providerId, e.event.removed);
39
- }
40
- this.updateBadgeCount();
41
- }));
42
- this._register(this._authenticationService.onDidUnregisterAuthenticationProvider(e => {
43
- const accessRequests = this._sessionAccessRequestItems.get(e.id) || {};
44
- ( Object.keys(accessRequests)).forEach(extensionId => {
45
- this.removeAccessRequest(e.id, extensionId);
46
- });
47
- }));
48
- }
49
- async updateNewSessionRequests(providerId, addedSessions) {
50
- const existingRequestsForProvider = this._signInRequestItems.get(providerId);
51
- if (!existingRequestsForProvider) {
52
- return;
53
- }
54
- ( Object.keys(existingRequestsForProvider)).forEach(requestedScopes => {
55
- if (( addedSessions.some(
56
- session => session.scopes.slice().join(SCOPESLIST_SEPARATOR) === requestedScopes
57
- ))) {
58
- const sessionRequest = existingRequestsForProvider[requestedScopes];
59
- sessionRequest?.disposables.forEach(item => item.dispose());
60
- delete existingRequestsForProvider[requestedScopes];
61
- if (( Object.keys(existingRequestsForProvider)).length === 0) {
62
- this._signInRequestItems.delete(providerId);
63
- }
64
- else {
65
- this._signInRequestItems.set(providerId, existingRequestsForProvider);
66
- }
67
- }
68
- });
69
- }
70
- async updateAccessRequests(providerId, removedSessions) {
71
- const providerRequests = this._sessionAccessRequestItems.get(providerId);
72
- if (providerRequests) {
73
- ( Object.keys(providerRequests)).forEach(extensionId => {
74
- removedSessions.forEach(removed => {
75
- const indexOfSession = providerRequests[extensionId].possibleSessions.findIndex(session => session.id === removed.id);
76
- if (indexOfSession) {
77
- providerRequests[extensionId].possibleSessions.splice(indexOfSession, 1);
78
- }
79
- });
80
- if (!providerRequests[extensionId].possibleSessions.length) {
81
- this.removeAccessRequest(providerId, extensionId);
82
- }
83
- });
84
- }
85
- }
86
- updateBadgeCount() {
87
- this._accountBadgeDisposable.clear();
88
- let numberOfRequests = 0;
89
- this._signInRequestItems.forEach(providerRequests => {
90
- ( Object.keys(providerRequests)).forEach(request => {
91
- numberOfRequests += providerRequests[request].requestingExtensionIds.length;
92
- });
93
- });
94
- this._sessionAccessRequestItems.forEach(accessRequest => {
95
- numberOfRequests += ( Object.keys(accessRequest)).length;
96
- });
97
- if (numberOfRequests > 0) {
98
- const badge = ( new NumberBadge(numberOfRequests, () => ( localizeWithPath(
99
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
100
- 'sign in',
101
- "Sign in requested"
102
- ))));
103
- this._accountBadgeDisposable.value = this.activityService.showAccountsActivity({ badge });
104
- }
105
- }
106
- removeAccessRequest(providerId, extensionId) {
107
- const providerRequests = this._sessionAccessRequestItems.get(providerId) || {};
108
- if (providerRequests[extensionId]) {
109
- dispose(providerRequests[extensionId].disposables);
110
- delete providerRequests[extensionId];
111
- this.updateBadgeCount();
112
- }
113
- }
114
- updateSessionPreference(providerId, extensionId, session) {
115
- const key = `${extensionId}-${providerId}-${session.scopes.join(' ')}`;
116
- this.storageService.store(key, session.id, 1 , 1 );
117
- this.storageService.store(key, session.id, -1 , 1 );
118
- }
119
- getSessionPreference(providerId, extensionId, scopes) {
120
- const key = `${extensionId}-${providerId}-${scopes.join(' ')}`;
121
- return this.storageService.get(key, 1 ) ?? this.storageService.get(key, -1 );
122
- }
123
- removeSessionPreference(providerId, extensionId, scopes) {
124
- const key = `${extensionId}-${providerId}-${scopes.join(' ')}`;
125
- this.storageService.remove(key, 1 );
126
- this.storageService.remove(key, -1 );
127
- }
128
- async showGetSessionPrompt(provider, accountName, extensionId, extensionName) {
129
- let SessionPromptChoice;
130
- ( (function(SessionPromptChoice) {
131
- SessionPromptChoice[SessionPromptChoice["Allow"] = 0] = "Allow";
132
- SessionPromptChoice[SessionPromptChoice["Deny"] = 1] = "Deny";
133
- SessionPromptChoice[SessionPromptChoice["Cancel"] = 2] = "Cancel";
134
- })(SessionPromptChoice || (SessionPromptChoice = {})));
135
- const { result } = await this.dialogService.prompt({
136
- type: Severity.Info,
137
- message: ( localizeWithPath(
138
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
139
- 'confirmAuthenticationAccess',
140
- "The extension '{0}' wants to access the {1} account '{2}'.",
141
- extensionName,
142
- provider.label,
143
- accountName
144
- )),
145
- buttons: [
146
- {
147
- label: ( localizeWithPath(
148
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
149
- { key: 'allow', comment: ['&& denotes a mnemonic'] },
150
- "&&Allow"
151
- )),
152
- run: () => SessionPromptChoice.Allow
153
- },
154
- {
155
- label: ( localizeWithPath(
156
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
157
- { key: 'deny', comment: ['&& denotes a mnemonic'] },
158
- "&&Deny"
159
- )),
160
- run: () => SessionPromptChoice.Deny
161
- }
162
- ],
163
- cancelButton: {
164
- run: () => SessionPromptChoice.Cancel
165
- }
166
- });
167
- if (result !== SessionPromptChoice.Cancel) {
168
- this._authenticationAccessService.updateAllowedExtensions(provider.id, accountName, [{ id: extensionId, name: extensionName, allowed: result === SessionPromptChoice.Allow }]);
169
- this.removeAccessRequest(provider.id, extensionId);
170
- }
171
- return result === SessionPromptChoice.Allow;
172
- }
173
- async selectSession(providerId, extensionId, extensionName, scopes, availableSessions) {
174
- return ( new Promise((resolve, reject) => {
175
- if (!availableSessions.length) {
176
- reject('No available sessions');
177
- return;
178
- }
179
- const quickPick = this.quickInputService.createQuickPick();
180
- quickPick.ignoreFocusOut = true;
181
- const items = ( availableSessions.map(session => {
182
- return {
183
- label: session.account.label,
184
- session: session
185
- };
186
- }));
187
- items.push({
188
- label: ( localizeWithPath(
189
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
190
- 'useOtherAccount',
191
- "Sign in to another account"
192
- ))
193
- });
194
- quickPick.items = items;
195
- quickPick.title = ( localizeWithPath(
196
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
197
- {
198
- key: 'selectAccount',
199
- comment: ['The placeholder {0} is the name of an extension. {1} is the name of the type of account, such as Microsoft or GitHub.']
200
- },
201
- "The extension '{0}' wants to access a {1} account",
202
- extensionName,
203
- this._authenticationService.getProvider(providerId).label
204
- ));
205
- quickPick.placeholder = ( localizeWithPath(
206
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
207
- 'getSessionPlateholder',
208
- "Select an account for '{0}' to use or Esc to cancel",
209
- extensionName
210
- ));
211
- quickPick.onDidAccept(async (_) => {
212
- const session = quickPick.selectedItems[0].session ?? (await this._authenticationService.createSession(providerId, scopes));
213
- const accountName = session.account.label;
214
- this._authenticationAccessService.updateAllowedExtensions(providerId, accountName, [{ id: extensionId, name: extensionName, allowed: true }]);
215
- this.updateSessionPreference(providerId, extensionId, session);
216
- this.removeAccessRequest(providerId, extensionId);
217
- quickPick.dispose();
218
- resolve(session);
219
- });
220
- quickPick.onDidHide(_ => {
221
- if (!quickPick.selectedItems[0]) {
222
- reject('User did not consent to account access');
223
- }
224
- quickPick.dispose();
225
- });
226
- quickPick.show();
227
- }));
228
- }
229
- async completeSessionAccessRequest(provider, extensionId, extensionName, scopes) {
230
- const providerRequests = this._sessionAccessRequestItems.get(provider.id) || {};
231
- const existingRequest = providerRequests[extensionId];
232
- if (!existingRequest) {
233
- return;
234
- }
235
- if (!provider) {
236
- return;
237
- }
238
- const possibleSessions = existingRequest.possibleSessions;
239
- let session;
240
- if (provider.supportsMultipleAccounts) {
241
- try {
242
- session = await this.selectSession(provider.id, extensionId, extensionName, scopes, possibleSessions);
243
- }
244
- catch (_) {
245
- }
246
- }
247
- else {
248
- const approved = await this.showGetSessionPrompt(provider, possibleSessions[0].account.label, extensionId, extensionName);
249
- if (approved) {
250
- session = possibleSessions[0];
251
- }
252
- }
253
- if (session) {
254
- this._authenticationUsageService.addAccountUsage(provider.id, session.account.label, extensionId, extensionName);
255
- }
256
- }
257
- requestSessionAccess(providerId, extensionId, extensionName, scopes, possibleSessions) {
258
- const providerRequests = this._sessionAccessRequestItems.get(providerId) || {};
259
- const hasExistingRequest = providerRequests[extensionId];
260
- if (hasExistingRequest) {
261
- return;
262
- }
263
- const provider = this._authenticationService.getProvider(providerId);
264
- const menuItem = ( MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
265
- group: '3_accessRequests',
266
- command: {
267
- id: `${providerId}${extensionId}Access`,
268
- title: ( localizeWithPath(
269
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
270
- {
271
- key: 'accessRequest',
272
- comment: [`The placeholder {0} will be replaced with an authentication provider''s label. {1} will be replaced with an extension name. (1) is to indicate that this menu item contributes to a badge count`]
273
- },
274
- "Grant access to {0} for {1}... (1)",
275
- provider.label,
276
- extensionName
277
- ))
278
- }
279
- }));
280
- const accessCommand = CommandsRegistry.registerCommand({
281
- id: `${providerId}${extensionId}Access`,
282
- handler: async (accessor) => {
283
- this.completeSessionAccessRequest(provider, extensionId, extensionName, scopes);
284
- }
285
- });
286
- providerRequests[extensionId] = { possibleSessions, disposables: [menuItem, accessCommand] };
287
- this._sessionAccessRequestItems.set(providerId, providerRequests);
288
- this.updateBadgeCount();
289
- }
290
- async requestNewSession(providerId, scopes, extensionId, extensionName) {
291
- if (!this._authenticationService.isAuthenticationProviderRegistered(providerId)) {
292
- await ( new Promise((resolve, _) => {
293
- const dispose = this._authenticationService.onDidRegisterAuthenticationProvider(e => {
294
- if (e.id === providerId) {
295
- dispose.dispose();
296
- resolve();
297
- }
298
- });
299
- }));
300
- }
301
- let provider;
302
- try {
303
- provider = this._authenticationService.getProvider(providerId);
304
- }
305
- catch (_e) {
306
- return;
307
- }
308
- const providerRequests = this._signInRequestItems.get(providerId);
309
- const scopesList = scopes.join(SCOPESLIST_SEPARATOR);
310
- const extensionHasExistingRequest = providerRequests
311
- && providerRequests[scopesList]
312
- && providerRequests[scopesList].requestingExtensionIds.includes(extensionId);
313
- if (extensionHasExistingRequest) {
314
- return;
315
- }
316
- const commandId = `${providerId}:${extensionId}:signIn${( Object.keys(providerRequests || [])).length}`;
317
- const menuItem = ( MenuRegistry.appendMenuItem(MenuId.AccountsContext, {
318
- group: '2_signInRequests',
319
- command: {
320
- id: commandId,
321
- title: ( localizeWithPath(
322
- 'vs/workbench/services/authentication/browser/authenticationExtensionsService',
323
- {
324
- key: 'signInRequest',
325
- comment: [`The placeholder {0} will be replaced with an authentication provider's label. {1} will be replaced with an extension name. (1) is to indicate that this menu item contributes to a badge count.`]
326
- },
327
- "Sign in with {0} to use {1} (1)",
328
- provider.label,
329
- extensionName
330
- ))
331
- }
332
- }));
333
- const signInCommand = CommandsRegistry.registerCommand({
334
- id: commandId,
335
- handler: async (accessor) => {
336
- const authenticationService = accessor.get(IAuthenticationService);
337
- const session = await authenticationService.createSession(providerId, scopes);
338
- this._authenticationAccessService.updateAllowedExtensions(providerId, session.account.label, [{ id: extensionId, name: extensionName, allowed: true }]);
339
- this.updateSessionPreference(providerId, extensionId, session);
340
- }
341
- });
342
- if (providerRequests) {
343
- const existingRequest = providerRequests[scopesList] || { disposables: [], requestingExtensionIds: [] };
344
- providerRequests[scopesList] = {
345
- disposables: [...existingRequest.disposables, menuItem, signInCommand],
346
- requestingExtensionIds: [...existingRequest.requestingExtensionIds, extensionId]
347
- };
348
- this._signInRequestItems.set(providerId, providerRequests);
349
- }
350
- else {
351
- this._signInRequestItems.set(providerId, {
352
- [scopesList]: {
353
- disposables: [menuItem, signInCommand],
354
- requestingExtensionIds: [extensionId]
355
- }
356
- });
357
- }
358
- this.updateBadgeCount();
359
- }
360
- };
361
- AuthenticationExtensionsService = ( __decorate([
362
- ( __param(0, IActivityService)),
363
- ( __param(1, IStorageService)),
364
- ( __param(2, IDialogService)),
365
- ( __param(3, IQuickInputService)),
366
- ( __param(4, IAuthenticationService)),
367
- ( __param(5, IAuthenticationUsageService)),
368
- ( __param(6, IAuthenticationAccessService))
369
- ], AuthenticationExtensionsService));
370
-
371
- export { AuthenticationExtensionsService };