Skip to content

Commit fc78a27

Browse files
committed
feat: support AuthenticationForceNewSessionOptions
1 parent 3383a0d commit fc78a27

3 files changed

Lines changed: 66 additions & 44 deletions

File tree

packages/core-common/src/types/authentication.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,3 @@ export interface SessionRequest {
106106
export interface SessionRequestInfo {
107107
[scopes: string]: SessionRequest;
108108
}
109-
110-
export interface AuthenticationGetSessionOptions {
111-
createIfNone: boolean;
112-
clearSessionPreference: boolean;
113-
forceNewSession?: boolean | { detail: string };
114-
silent?: boolean;
115-
}

packages/extension/src/browser/vscode/api/main.thread.authentication.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Autowired, INJECTOR_TOKEN, Injectable, Injector } from '@opensumi/di';
22
import { IRPCProtocol } from '@opensumi/ide-connection';
33
import { Disposable, ILogger, QuickPickService, formatLocalize, localize } from '@opensumi/ide-core-browser';
44
import {
5-
AuthenticationGetSessionOptions,
65
AuthenticationSession,
76
AuthenticationSessionsChangeEvent,
87
IAuthenticationProvider,
@@ -13,6 +12,8 @@ import { IDialogService, IMessageService } from '@opensumi/ide-overlay';
1312
import { ExtHostAPIIdentifier, IExtHostAuthentication, IMainThreadAuthentication } from '../../../common/vscode';
1413
import { IActivationEventService } from '../../types';
1514

15+
import type vscode from 'vscode';
16+
1617
@Injectable({ multiple: true })
1718
export class MainThreadAuthenticationProvider extends Disposable implements IAuthenticationProvider {
1819
@Autowired(IAuthenticationService)
@@ -248,7 +249,7 @@ export class MainThreadAuthentication extends Disposable implements IMainThreadA
248249
scopes: string[],
249250
extensionId: string,
250251
extensionName: string,
251-
options: AuthenticationGetSessionOptions,
252+
options: vscode.AuthenticationGetSessionOptions,
252253
): Promise<AuthenticationSession | undefined> {
253254
const sessions = await this.authenticationService.getSessions(providerId, scopes, true);
254255
const supportsMultipleAccounts = this.authenticationService.supportsMultipleAccounts(providerId);

packages/types/vscode/typings/vscode.authentication.d.ts

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ declare module 'vscode' {
4040
readonly label: string;
4141
}
4242

43+
/**
44+
* Optional options to be used when calling {@link authentication.getSession} with the flag `forceNewSession`.
45+
*/
46+
export interface AuthenticationForceNewSessionOptions {
47+
/**
48+
* An optional message that will be displayed to the user when we ask to re-authenticate. Providing additional context
49+
* as to why you are asking a user to re-authenticate can help increase the odds that they will accept.
50+
*/
51+
detail?: string;
52+
}
4353

4454
/**
4555
* Options to be used when getting an {@link AuthenticationSession} from an {@link AuthenticationProvider}.
@@ -60,14 +70,17 @@ declare module 'vscode' {
6070
createIfNone?: boolean;
6171

6272
/**
63-
* Whether we should attempt to reauthenticate even if there is already a session available.
64-
*
65-
* If true, a modal dialog will be shown asking the user to sign in again. This is mostly used for scenarios
66-
* where the token needs to be re minted because it has lost some authorization.
67-
*
68-
* Defaults to false.
69-
*/
70-
forceNewSession?: boolean | { detail: string };
73+
* Whether we should attempt to reauthenticate even if there is already a session available.
74+
*
75+
* If true, a modal dialog will be shown asking the user to sign in again. This is mostly used for scenarios
76+
* where the token needs to be re minted because it has lost some authorization.
77+
*
78+
* If there are no existing sessions and forceNewSession is true, it will behave identically to
79+
* {@link AuthenticationGetSessionOptions.createIfNone createIfNone}.
80+
*
81+
* This defaults to false.
82+
*/
83+
forceNewSession?: boolean | AuthenticationForceNewSessionOptions;
7184

7285

7386
/**
@@ -202,34 +215,49 @@ declare module 'vscode' {
202215
*/
203216
export namespace authentication {
204217
/**
205-
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
206-
* registered, or if the user does not consent to sharing authentication information with
207-
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
208-
* quickpick to select which account they would like to use.
209-
*
210-
* Currently, there are only two authentication providers that are contributed from built in extensions
211-
* to VS Code that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
212-
* @param providerId The id of the provider to use
213-
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
214-
* @param options The {@link GetSessionOptions} to use
215-
* @returns A thenable that resolves to an authentication session
216-
*/
217-
export function getSession(providerId: string, scopes: string[], options: AuthenticationGetSessionOptions & { createIfNone: true }): Thenable<AuthenticationSession>;
218+
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
219+
* registered, or if the user does not consent to sharing authentication information with
220+
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
221+
* quickpick to select which account they would like to use.
222+
*
223+
* Currently, there are only two authentication providers that are contributed from built in extensions
224+
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
225+
* @param providerId The id of the provider to use
226+
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
227+
* @param options The {@link AuthenticationGetSessionOptions} to use
228+
* @returns A thenable that resolves to an authentication session
229+
*/
230+
export function getSession(providerId: string, scopes: readonly string[], options: AuthenticationGetSessionOptions & { /** */createIfNone: true }): Thenable<AuthenticationSession>;
218231

219-
/**
220-
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
221-
* registered, or if the user does not consent to sharing authentication information with
222-
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
223-
* quickpick to select which account they would like to use.
224-
*
225-
* Currently, there are only two authentication providers that are contributed from built in extensions
226-
* to VS Code that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
227-
* @param providerId The id of the provider to use
228-
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
229-
* @param options The {@link GetSessionOptions} to use
230-
* @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions
231-
*/
232-
export function getSession(providerId: string, scopes: string[], options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
232+
/**
233+
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
234+
* registered, or if the user does not consent to sharing authentication information with
235+
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
236+
* quickpick to select which account they would like to use.
237+
*
238+
* Currently, there are only two authentication providers that are contributed from built in extensions
239+
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
240+
* @param providerId The id of the provider to use
241+
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
242+
* @param options The {@link AuthenticationGetSessionOptions} to use
243+
* @returns A thenable that resolves to an authentication session
244+
*/
245+
export function getSession(providerId: string, scopes: readonly string[], options: AuthenticationGetSessionOptions & { /** literal-type defines return type */forceNewSession: true | AuthenticationForceNewSessionOptions }): Thenable<AuthenticationSession>;
246+
247+
/**
248+
* Get an authentication session matching the desired scopes. Rejects if a provider with providerId is not
249+
* registered, or if the user does not consent to sharing authentication information with
250+
* the extension. If there are multiple sessions with the same scopes, the user will be shown a
251+
* quickpick to select which account they would like to use.
252+
*
253+
* Currently, there are only two authentication providers that are contributed from built in extensions
254+
* to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'.
255+
* @param providerId The id of the provider to use
256+
* @param scopes A list of scopes representing the permissions requested. These are dependent on the authentication provider
257+
* @param options The {@link AuthenticationGetSessionOptions} to use
258+
* @returns A thenable that resolves to an authentication session if available, or undefined if there are no sessions
259+
*/
260+
export function getSession(providerId: string, scopes: readonly string[], options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>;
233261

234262
/**
235263
* An {@link Event} which fires when the authentication sessions of an authentication provider have

0 commit comments

Comments
 (0)