mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-22 01:29:04 +01:00
Have forceNewSession behave like createIfNone if no sessions are present (#148819)
* Have forceNewSession behave like createIfNone if no sessions are present * include note in vscode.d.ts about forceNewSesssion behavior
This commit is contained in:
committed by
GitHub
parent
9991dffebf
commit
6c8d8a2654
@@ -210,9 +210,6 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
|
||||
const supportsMultipleAccounts = this.authenticationService.supportsMultipleAccounts(providerId);
|
||||
|
||||
// Error cases
|
||||
if (options.forceNewSession && !sessions.length) {
|
||||
throw new Error('No existing sessions found.');
|
||||
}
|
||||
if (options.forceNewSession && options.createIfNone) {
|
||||
throw new Error('Invalid combination of options. Please remove one of the following: forceNewSession, createIfNone');
|
||||
}
|
||||
@@ -247,7 +244,11 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
|
||||
if (options.createIfNone || options.forceNewSession) {
|
||||
const providerName = this.authenticationService.getLabel(providerId);
|
||||
const detail = (typeof options.forceNewSession === 'object') ? options.forceNewSession!.detail : undefined;
|
||||
const isAllowed = await this.loginPrompt(providerName, extensionName, !!options.forceNewSession, detail);
|
||||
|
||||
// We only want to show the "recreating session" prompt if we are using forceNewSession & there are sessions
|
||||
// that we will be "forcing through".
|
||||
const recreatingSession = !!(options.forceNewSession && sessions.length);
|
||||
const isAllowed = await this.loginPrompt(providerName, extensionName, recreatingSession, detail);
|
||||
if (!isAllowed) {
|
||||
throw new Error('User did not consent to login.');
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ suite('ExtHostAuthentication', () => {
|
||||
assert.strictEqual(session.scopes[0], session2?.scopes[0]);
|
||||
});
|
||||
|
||||
test('forceNewSession - true', async () => {
|
||||
test('forceNewSession - true - existing session', async () => {
|
||||
const scopes = ['foo'];
|
||||
const session1 = await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
@@ -235,6 +235,20 @@ suite('ExtHostAuthentication', () => {
|
||||
assert.notStrictEqual(session1.accessToken, session2?.accessToken);
|
||||
});
|
||||
|
||||
// Should behave like createIfNone: true
|
||||
test('forceNewSession - true - no existing session', async () => {
|
||||
const scopes = ['foo'];
|
||||
const session = await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test',
|
||||
scopes,
|
||||
{
|
||||
forceNewSession: true
|
||||
});
|
||||
assert.strictEqual(session?.id, '1');
|
||||
assert.strictEqual(session?.scopes[0], 'foo');
|
||||
});
|
||||
|
||||
test('forceNewSession - detail', async () => {
|
||||
const scopes = ['foo'];
|
||||
const session1 = await extHostAuthentication.getSession(
|
||||
@@ -350,21 +364,6 @@ suite('ExtHostAuthentication', () => {
|
||||
|
||||
//#region error cases
|
||||
|
||||
test('forceNewSession with no sessions', async () => {
|
||||
try {
|
||||
await extHostAuthentication.getSession(
|
||||
extensionDescription,
|
||||
'test',
|
||||
['foo'],
|
||||
{
|
||||
forceNewSession: true
|
||||
});
|
||||
assert.fail('should have thrown an Error.');
|
||||
} catch (e) {
|
||||
assert.strictEqual(e.message, 'No existing sessions found.');
|
||||
}
|
||||
});
|
||||
|
||||
test('createIfNone and forceNewSession', async () => {
|
||||
try {
|
||||
await extHostAuthentication.getSession(
|
||||
|
||||
Reference in New Issue
Block a user