Skip to content

Commit e606824

Browse files
Limit local GitHub restriction for web cases to GitHub git provider
1 parent ff18fe8 commit e606824

File tree

4 files changed

+65
-35
lines changed

4 files changed

+65
-35
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { authentication } from 'vscode';
2+
import { wrapForForcedInsecureSSL } from '@env/fetch';
3+
import type { IntegrationId } from '../../../../constants.integrations';
4+
import type { Container } from '../../../../container';
5+
import { sequentialize } from '../../../../system/function';
6+
import type { IntegrationAuthenticationSessionDescriptor } from '../../../integrations/authentication/integrationAuthentication';
7+
import type { ProviderAuthenticationSession } from '../../../integrations/authentication/models';
8+
9+
export async function getBuiltInIntegrationSession(
10+
container: Container,
11+
id: IntegrationId,
12+
descriptor: IntegrationAuthenticationSessionDescriptor,
13+
options?:
14+
| { createIfNeeded: true; silent?: never; forceNewSession?: never }
15+
| { createIfNeeded?: never; silent: true; forceNewSession?: never }
16+
| { createIfNeeded?: never; silent?: never; forceNewSession: true },
17+
): Promise<ProviderAuthenticationSession | undefined> {
18+
return sequentialize(() =>
19+
wrapForForcedInsecureSSL(
20+
container.integrations.ignoreSSLErrors({ id: id, domain: descriptor.domain }),
21+
async () => {
22+
const session = await authentication.getSession(id, descriptor.scopes, {
23+
createIfNone: options?.createIfNeeded,
24+
silent: options?.silent,
25+
forceNewSession: options?.forceNewSession,
26+
});
27+
if (session == null) return undefined;
28+
29+
return {
30+
...session,
31+
cloud: false,
32+
};
33+
},
34+
),
35+
)();
36+
}

src/plus/integrations/authentication/integrationAuthentication.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import type { CancellationToken, Disposable, Event, Uri } from 'vscode';
22
import { authentication, EventEmitter, window } from 'vscode';
3-
import { wrapForForcedInsecureSSL } from '@env/fetch';
43
import type { IntegrationId } from '../../../constants.integrations';
54
import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
65
import type { IntegrationAuthenticationKeys, StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
76
import type { Sources } from '../../../constants.telemetry';
87
import type { Container } from '../../../container';
98
import { gate } from '../../../system/decorators/-webview/gate';
109
import { debug, log } from '../../../system/decorators/log';
11-
import { sequentialize } from '../../../system/decorators/serialize';
1210
import type { DeferredEventExecutor } from '../../../system/event';
11+
import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils';
1312
import {
1413
isCloudSelfHostedIntegrationId,
1514
isSelfHostedIntegrationId,
@@ -480,29 +479,18 @@ class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvid
480479
}
481480

482481
@debug()
483-
@sequentialize()
484482
override async getSession(
485483
descriptor?: IntegrationAuthenticationSessionDescriptor,
486484
options?: { createIfNeeded?: boolean; forceNewSession?: boolean },
487485
): Promise<ProviderAuthenticationSession | undefined> {
488486
if (descriptor == null) return undefined;
489487

490488
const { createIfNeeded, forceNewSession } = options ?? {};
491-
return wrapForForcedInsecureSSL(
492-
this.container.integrations.ignoreSSLErrors({ id: this.authProviderId, domain: descriptor?.domain }),
493-
async () => {
494-
const session = await authentication.getSession(this.authProviderId, descriptor.scopes, {
495-
createIfNone: forceNewSession ? undefined : createIfNeeded,
496-
silent: !createIfNeeded && !forceNewSession ? true : undefined,
497-
forceNewSession: forceNewSession ? true : undefined,
498-
});
499-
if (session == null) return undefined;
500-
501-
return {
502-
...session,
503-
cloud: false,
504-
};
505-
},
489+
return getBuiltInIntegrationSession(
490+
this.container,
491+
this.authProviderId,
492+
descriptor,
493+
forceNewSession ? { forceNewSession: true } : createIfNeeded ? { createIfNeeded: true } : { silent: true },
506494
);
507495
}
508496
}

src/plus/integrations/authentication/models.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { AuthenticationSession } from 'vscode';
2-
import { isWeb } from '@env/platform';
32
import type { IntegrationId, SupportedCloudIntegrationIds } from '../../../constants.integrations';
43
import {
54
HostingIntegrationId,
@@ -56,15 +55,9 @@ export type CloudIntegrationAuthType = 'oauth' | 'pat';
5655
export const CloudIntegrationAuthenticationUriPathPrefix = 'did-authenticate-cloud-integration';
5756

5857
export function getSupportedCloudIntegrationIds(): SupportedCloudIntegrationIds[] {
59-
let supportedCloudIntegrationIds = configuration.get('cloudIntegrations.enabled', undefined, true)
58+
return configuration.get('cloudIntegrations.enabled', undefined, true)
6059
? supportedOrderedCloudIntegrationIds
6160
: supportedOrderedCloudIssueIntegrationIds;
62-
if (isWeb) {
63-
// We always have a local GitHub session on vscode.dev and github.dev
64-
supportedCloudIntegrationIds = supportedCloudIntegrationIds.filter(id => id !== HostingIntegrationId.GitHub);
65-
}
66-
67-
return supportedCloudIntegrationIds;
6861
}
6962

7063
export function isSupportedCloudIntegrationId(id: string): id is SupportedCloudIntegrationIds {

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import { isAbsolute, maybeUri, normalizePath } from '../../../../system/path';
7777
import { asSettled, getSettledValue } from '../../../../system/promise';
7878
import type { CachedBlame, TrackedGitDocument } from '../../../../trackers/trackedDocument';
7979
import { GitDocumentState } from '../../../../trackers/trackedDocument';
80+
import { getBuiltInIntegrationSession } from '../../../gk/utils/-webview/integrationAuthentication.utils';
8081
import type { GitHubAuthorityMetadata, Metadata, RemoteHubApi } from '../../../remotehub';
8182
import { getRemoteHubApi, HeadType, RepositoryRefType } from '../../../remotehub';
8283
import type {
@@ -1464,24 +1465,36 @@ export class GitHubGitProvider implements GitProvider, Disposable {
14641465
async function getSession(this: GitHubGitProvider): Promise<AuthenticationSession> {
14651466
let skip = this.container.storage.get(`provider:authentication:skip:${this.descriptor.id}`, false);
14661467
const authenticationProvider = await this.authenticationService.get(this.authenticationProviderId);
1468+
let options:
1469+
| { forceNewSession: true; createIfNeeded?: never; silent?: never }
1470+
| { forceNewSession?: never; createIfNeeded: true; silent?: never }
1471+
| { forceNewSession?: never; createIfNeeded?: never; silent: true } = isWeb
1472+
? { createIfNeeded: true }
1473+
: { silent: true };
14671474

14681475
try {
1469-
let session;
14701476
if (force) {
14711477
skip = false;
14721478
void this.container.storage.delete(`provider:authentication:skip:${this.descriptor.id}`);
1473-
1474-
session = await authenticationProvider.getSession(this.authenticationDescriptor, {
1475-
forceNewSession: true,
1476-
});
1479+
options = { forceNewSession: true };
14771480
} else if (!skip && !silent) {
1478-
session = await authenticationProvider.getSession(this.authenticationDescriptor, {
1479-
createIfNeeded: true,
1480-
});
1481+
options = { createIfNeeded: true };
14811482
} else {
1482-
session = await authenticationProvider.getSession(this.authenticationDescriptor);
1483+
options = isWeb ? { createIfNeeded: true } : { silent: true };
14831484
}
14841485

1486+
const session = isWeb
1487+
? await getBuiltInIntegrationSession(
1488+
this.container,
1489+
HostingIntegrationId.GitHub,
1490+
this.authenticationDescriptor,
1491+
options,
1492+
)
1493+
: await authenticationProvider.getSession(
1494+
this.authenticationDescriptor,
1495+
options.silent ? undefined : options,
1496+
);
1497+
14851498
if (session != null) return session;
14861499

14871500
throw new Error('User did not consent');

0 commit comments

Comments
 (0)