Skip to content

Commit 56c0f92

Browse files
committed
Adds authentication type to integration sessions
Introduces a `type` property to authentication session and token information objects. * Sets the type to 'pat' for self-managed GitHub and GitLab integrations, indicating a Personal Access Token. * Initializes the type as `undefined` for built-in sessions and GitKraken tokens where a specific method isn't specified by the provider. * Ensures the `type` property is propagated and handled correctly across integration authentication flows and error reporting. (#4880, #4896)
1 parent ae79310 commit 56c0f92

8 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/plus/gk/serverConnection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export class ServerConnection implements Disposable {
270270

271271
const gitkrakenTokenInfo: TokenInfo<'gitkraken'> = toTokenInfo('gitkraken', token, {
272272
cloud: true,
273+
type: undefined,
273274
scopes: undefined,
274275
});
275276

src/plus/gk/utils/-webview/integrationAuthentication.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const getBuiltInIntegrationSession = sequentialize(
4747
return {
4848
...session,
4949
cloud: false,
50+
type: undefined,
5051
domain: descriptor.domain,
5152
};
5253
} catch (ex) {

src/plus/integrations/authentication/configuredIntegrationService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integratio
1313
import { providersMetadata } from '../providers/models.js';
1414
import { isGitSelfManagedHostIntegrationId } from '../utils/-webview/integration.utils.js';
1515
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider.js';
16-
import type { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from './models.js';
16+
import type {
17+
CloudIntegrationAuthType,
18+
ConfiguredIntegrationDescriptor,
19+
ProviderAuthenticationSession,
20+
} from './models.js';
1721

1822
interface StoredSession {
1923
id: string;
2024
accessToken: string;
2125
account?: { label?: string; displayName?: string; id: string };
2226
scopes: string[];
2327
cloud?: boolean;
28+
type: CloudIntegrationAuthType | undefined;
2429
expiresAt?: string;
2530
domain?: string;
2631
protocol?: string;
@@ -431,5 +436,6 @@ function convertStoredSessionToSession(
431436
expiresAt: storedSession.expiresAt ? new Date(storedSession.expiresAt) : undefined,
432437
domain: storedSession.domain ?? descriptor.domain,
433438
protocol: storedSession.protocol,
439+
type: storedSession.type,
434440
};
435441
}

src/plus/integrations/authentication/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export class GitHubEnterpriseAuthenticationProvider extends LocalIntegrationAuth
123123
label: '',
124124
},
125125
cloud: false,
126+
type: 'pat',
126127
domain: descriptor.domain,
127128
};
128129
}

src/plus/integrations/authentication/gitlab.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class GitLabLocalAuthenticationProvider extends LocalIntegrationAuthentic
8888
label: '',
8989
},
9090
cloud: false,
91+
type: 'pat',
9192
domain: descriptor.domain,
9293
};
9394
}

src/plus/integrations/authentication/integrationAuthenticationProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export abstract class CloudIntegrationAuthenticationProvider<
298298
label: '',
299299
},
300300
cloud: true,
301+
type: session.type,
301302
expiresAt: new Date(session.expiresIn * 1000 + Date.now()),
302303
// Note: do not use the session's domain, because the format is different than in our model
303304
domain: descriptor.domain,

src/plus/integrations/authentication/models.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { configuration } from '../../../system/-webview/configuration.js';
1212

1313
export interface ProviderAuthenticationSession extends AuthenticationSession {
1414
readonly cloud: boolean;
15+
readonly type: CloudIntegrationAuthType | undefined;
1516
readonly expiresAt?: Date;
1617
readonly domain: string;
1718
readonly protocol?: string;
@@ -26,7 +27,7 @@ export interface TokenInfo<T extends IntegrationIds | 'gitkraken' = IntegrationI
2627
*/
2728
readonly microHash: string | undefined;
2829
readonly cloud: boolean;
29-
readonly type?: CloudIntegrationAuthType;
30+
readonly type: CloudIntegrationAuthType | undefined;
3031
readonly scopes: readonly string[] | undefined;
3132
readonly expiresAt?: Date;
3233
}
@@ -38,12 +39,13 @@ export interface TokenWithInfo<T extends IntegrationIds = IntegrationIds> extend
3839
export function toTokenInfo<T extends IntegrationIds | 'gitkraken'>(
3940
providerId: T,
4041
accessToken: string | undefined,
41-
info: { cloud: boolean; scopes?: readonly string[]; expiresAt?: Date },
42+
info: { cloud: boolean; type: CloudIntegrationAuthType | undefined; scopes?: readonly string[]; expiresAt?: Date },
4243
): TokenInfo<T> {
4344
return {
4445
providerId: providerId,
4546
microHash: microhash(accessToken),
4647
cloud: info.cloud,
48+
type: info.type,
4749
scopes: info.scopes,
4850
expiresAt: info.expiresAt,
4951
};

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,11 +1118,13 @@ export class GitHubGitProvider implements GitProvider, Disposable {
11181118
}
11191119
}
11201120
throw new AuthenticationError(
1121+
// scopes and other fields are undefined here because the token has not been issues:
11211122
{
11221123
providerId: this.authenticationProviderId,
11231124
microHash: undefined,
11241125
cloud: false,
1125-
scopes: undefined, // scopes are undefined because the token has not been issues
1126+
type: undefined,
1127+
scopes: undefined,
11261128
},
11271129
AuthenticationErrorReason.UserDidNotConsent,
11281130
);
@@ -1131,11 +1133,13 @@ export class GitHubGitProvider implements GitProvider, Disposable {
11311133
Logger.error(ex);
11321134
debugger;
11331135
throw new AuthenticationError(
1136+
// scopes and other fields are undefined here because the token has not been issues:
11341137
{
11351138
providerId: this.authenticationProviderId,
11361139
microHash: undefined,
11371140
cloud: false,
1138-
scopes: undefined, // scopes are undefined because the token has not been issues
1141+
type: undefined,
1142+
scopes: undefined,
11391143
},
11401144
undefined,
11411145
ex,

0 commit comments

Comments
 (0)