Skip to content

Commit 9a14896

Browse files
committed
Use GHE auth provider if GHEC-DR URI is set
1 parent 871fc0b commit 9a14896

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

extensions/ql-vscode/src/common/authentication.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ export interface Credentials {
3131
* @returns An OAuth access token, or undefined.
3232
*/
3333
getExistingAccessToken(): Promise<string | undefined>;
34+
35+
/**
36+
* Returns the ID of the authentication provider to use.
37+
*/
38+
authProviderId: string;
3439
}

extensions/ql-vscode/src/common/vscode/authentication.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { authentication } from "vscode";
22
import type { Octokit } from "@octokit/rest";
33
import type { Credentials } from "../authentication";
44
import { AppOctokit } from "../octokit";
5-
6-
export const GITHUB_AUTH_PROVIDER_ID = "github";
5+
import { hasGhecDrUri } from "../../config";
76

87
// We need 'repo' scope for triggering workflows, 'gist' scope for exporting results to Gist,
98
// and 'read:packages' for reading private CodeQL packages.
@@ -39,7 +38,7 @@ export class VSCodeCredentials implements Credentials {
3938

4039
async getAccessToken(): Promise<string> {
4140
const session = await authentication.getSession(
42-
GITHUB_AUTH_PROVIDER_ID,
41+
this.authProviderId,
4342
SCOPES,
4443
{ createIfNone: true },
4544
);
@@ -49,11 +48,18 @@ export class VSCodeCredentials implements Credentials {
4948

5049
async getExistingAccessToken(): Promise<string | undefined> {
5150
const session = await authentication.getSession(
52-
GITHUB_AUTH_PROVIDER_ID,
51+
this.authProviderId,
5352
SCOPES,
5453
{ createIfNone: false },
5554
);
5655

5756
return session?.accessToken;
5857
}
58+
59+
public get authProviderId(): string {
60+
if (hasGhecDrUri()) {
61+
return "github-enterprise";
62+
}
63+
return "github";
64+
}
5965
}

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ import {
7878
REPO_STATES_FILENAME,
7979
writeRepoStates,
8080
} from "./repo-states-store";
81-
import { GITHUB_AUTH_PROVIDER_ID } from "../common/vscode/authentication";
8281
import { FetchError } from "node-fetch";
8382
import {
8483
showAndLogExceptionWithTelemetry,
@@ -750,7 +749,7 @@ export class VariantAnalysisManager
750749
private async onDidChangeSessions(
751750
event: AuthenticationSessionsChangeEvent,
752751
): Promise<void> {
753-
if (event.provider.id !== GITHUB_AUTH_PROVIDER_ID) {
752+
if (event.provider.id !== this.app.credentials.authProviderId) {
754753
return;
755754
}
756755

extensions/ql-vscode/test/factories/authentication.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function makeTestOctokit(octokit: Octokit): Credentials {
1515
"getExistingAccessToken not supported by test credentials",
1616
);
1717
},
18+
authProviderId: "github",
1819
};
1920
}
2021

0 commit comments

Comments
 (0)