Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/plus/gk/account/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
AuthenticationProviderAuthenticationSessionsChangeEvent,
AuthenticationSession,
} from 'vscode';
import { authentication, Disposable, EventEmitter, window } from 'vscode';
import { Disposable, EventEmitter, window } from 'vscode';
import { uuid } from '@env/crypto';
import type { Container, Environment } from '../../../container';
import { CancellationError } from '../../../errors';
Expand All @@ -27,7 +27,6 @@ interface StoredSession {

export const authenticationProviderId = 'gitlens+';
export const authenticationProviderScopes = ['gitlens'];
const authenticationLabel = 'GitKraken: GitLens';

export interface AuthenticationProviderOptions {
signUp?: boolean;
Expand Down Expand Up @@ -57,9 +56,6 @@ export class AccountAuthenticationProvider implements AuthenticationProvider, Di

this._disposable = Disposable.from(
this._authConnection,
authentication.registerAuthenticationProvider(authenticationProviderId, authenticationLabel, this, {
supportsMultipleAccounts: false,
}),
this.container.storage.onDidChangeSecrets(() => this.checkForUpdates()),
);
}
Expand Down Expand Up @@ -234,6 +230,20 @@ export class AccountAuthenticationProvider implements AuthenticationProvider, Di
}
}

public async getOrCreateSession(
scopes: string[],
createIfNeeded: boolean,
): Promise<AuthenticationSession | undefined> {
const session = (await this.getSessions(scopes))[0];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axosoft-ramint @eamodio

I'm not sure that this is the right way of accessing the session: retrieving an array of matching sessions and taking the first one. Can you confirm or suggest a better way?

if (session != null) {
return session;
}
if (!createIfNeeded) {
return undefined;
}
return this.createSession(scopes);
}

private async createSessionForToken(token: string, scopes: string[]): Promise<AuthenticationSession> {
const userInfo = await this._authConnection.getAccountInfo(token);
return {
Expand Down
11 changes: 5 additions & 6 deletions src/plus/gk/account/subscriptionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
StatusBarItem,
} from 'vscode';
import {
authentication,
CancellationTokenSource,
version as codeVersion,
Disposable,
Expand Down Expand Up @@ -50,7 +49,7 @@ import { getSubscriptionFromCheckIn } from '../checkin';
import type { ServerConnection } from '../serverConnection';
import { ensurePlusFeaturesEnabled } from '../utils';
import { AuthenticationContext } from './authenticationConnection';
import { authenticationProviderId, authenticationProviderScopes } from './authenticationProvider';
import { authenticationProviderScopes } from './authenticationProvider';
import type { Organization } from './organization';
import { getApplicablePromo } from './promos';
import type { Subscription } from './subscription';
Expand Down Expand Up @@ -1053,10 +1052,10 @@ export class SubscriptionService implements Disposable {
if (options != null && createIfNeeded) {
this.container.accountAuthentication.setOptionsForScopes(authenticationProviderScopes, options);
}
session = await authentication.getSession(authenticationProviderId, authenticationProviderScopes, {
createIfNone: createIfNeeded,
silent: !createIfNeeded,
});
session = await this.container.accountAuthentication.getOrCreateSession(
authenticationProviderScopes,
createIfNeeded,
);
} catch (ex) {
session = null;
if (options != null && createIfNeeded) {
Expand Down
Loading