Skip to content

Commit cf6766d

Browse files
authored
Change GK account authentication to no longer use the VS Code authentication system (#3524)
* Stop registering the authentication provider in VS Code authentication. (#3524) * Getting/creating a session honors `createIfNeeded` flag (#3524)
1 parent 77462fc commit cf6766d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/plus/gk/account/authenticationProvider.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
AuthenticationProviderAuthenticationSessionsChangeEvent,
44
AuthenticationSession,
55
} from 'vscode';
6-
import { authentication, Disposable, EventEmitter, window } from 'vscode';
6+
import { Disposable, EventEmitter, window } from 'vscode';
77
import { uuid } from '@env/crypto';
88
import type { Container, Environment } from '../../../container';
99
import { CancellationError } from '../../../errors';
@@ -27,7 +27,6 @@ interface StoredSession {
2727

2828
export const authenticationProviderId = 'gitlens+';
2929
export const authenticationProviderScopes = ['gitlens'];
30-
const authenticationLabel = 'GitKraken: GitLens';
3130

3231
export interface AuthenticationProviderOptions {
3332
signUp?: boolean;
@@ -57,9 +56,6 @@ export class AccountAuthenticationProvider implements AuthenticationProvider, Di
5756

5857
this._disposable = Disposable.from(
5958
this._authConnection,
60-
authentication.registerAuthenticationProvider(authenticationProviderId, authenticationLabel, this, {
61-
supportsMultipleAccounts: false,
62-
}),
6359
this.container.storage.onDidChangeSecrets(() => this.checkForUpdates()),
6460
);
6561
}
@@ -234,6 +230,20 @@ export class AccountAuthenticationProvider implements AuthenticationProvider, Di
234230
}
235231
}
236232

233+
public async getOrCreateSession(
234+
scopes: string[],
235+
createIfNeeded: boolean,
236+
): Promise<AuthenticationSession | undefined> {
237+
const session = (await this.getSessions(scopes))[0];
238+
if (session != null) {
239+
return session;
240+
}
241+
if (!createIfNeeded) {
242+
return undefined;
243+
}
244+
return this.createSession(scopes);
245+
}
246+
237247
private async createSessionForToken(token: string, scopes: string[]): Promise<AuthenticationSession> {
238248
const userInfo = await this._authConnection.getAccountInfo(token);
239249
return {

src/plus/gk/account/subscriptionService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
StatusBarItem,
88
} from 'vscode';
99
import {
10-
authentication,
1110
CancellationTokenSource,
1211
version as codeVersion,
1312
Disposable,
@@ -50,7 +49,7 @@ import { getSubscriptionFromCheckIn } from '../checkin';
5049
import type { ServerConnection } from '../serverConnection';
5150
import { ensurePlusFeaturesEnabled } from '../utils';
5251
import { AuthenticationContext } from './authenticationConnection';
53-
import { authenticationProviderId, authenticationProviderScopes } from './authenticationProvider';
52+
import { authenticationProviderScopes } from './authenticationProvider';
5453
import type { Organization } from './organization';
5554
import { getApplicablePromo } from './promos';
5655
import type { Subscription } from './subscription';
@@ -1053,10 +1052,10 @@ export class SubscriptionService implements Disposable {
10531052
if (options != null && createIfNeeded) {
10541053
this.container.accountAuthentication.setOptionsForScopes(authenticationProviderScopes, options);
10551054
}
1056-
session = await authentication.getSession(authenticationProviderId, authenticationProviderScopes, {
1057-
createIfNone: createIfNeeded,
1058-
silent: !createIfNeeded,
1059-
});
1055+
session = await this.container.accountAuthentication.getOrCreateSession(
1056+
authenticationProviderScopes,
1057+
createIfNeeded,
1058+
);
10601059
} catch (ex) {
10611060
session = null;
10621061
if (options != null && createIfNeeded) {

0 commit comments

Comments
 (0)