Skip to content

Commit b4478e9

Browse files
committed
Remove token for running a remote query
1 parent a715ce1 commit b4478e9

2 files changed

Lines changed: 12 additions & 33 deletions

File tree

extensions/ql-vscode/src/authentication.ts

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ const GITHUB_AUTH_PROVIDER_ID = 'github';
77
// https://docs.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps
88
const SCOPES = ['repo'];
99

10-
interface OctokitAndToken {
11-
octokit: Octokit.Octokit;
12-
token: string;
13-
}
14-
1510
/**
1611
* Handles authentication to GitHub, using the VS Code [authentication API](https://code.visualstudio.com/api/references/vscode-api#authentication).
1712
*/
1813
export class Credentials {
19-
private octokitAndToken: OctokitAndToken | undefined;
14+
private octokit: Octokit.Octokit | undefined;
2015

2116
// Explicitly make the constructor private, so that we can't accidentally call the constructor from outside the class
2217
// without also initializing the class.
@@ -26,20 +21,17 @@ export class Credentials {
2621
static async initialize(context: vscode.ExtensionContext): Promise<Credentials> {
2722
const c = new Credentials();
2823
c.registerListeners(context);
29-
c.octokitAndToken = await c.createOctokit(false);
24+
c.octokit = await c.createOctokit(false);
3025
return c;
3126
}
3227

33-
private async createOctokit(createIfNone: boolean): Promise<OctokitAndToken | undefined> {
28+
private async createOctokit(createIfNone: boolean): Promise<Octokit.Octokit | undefined> {
3429
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone });
3530

3631
if (session) {
37-
return {
38-
octokit: new Octokit.Octokit({
39-
auth: session.accessToken
40-
}),
41-
token: session.accessToken
42-
};
32+
return new Octokit.Octokit({
33+
auth: session.accessToken
34+
});
4335
} else {
4436
return undefined;
4537
}
@@ -49,33 +41,22 @@ export class Credentials {
4941
// Sessions are changed when a user logs in or logs out.
5042
context.subscriptions.push(vscode.authentication.onDidChangeSessions(async e => {
5143
if (e.provider.id === GITHUB_AUTH_PROVIDER_ID) {
52-
this.octokitAndToken = await this.createOctokit(false);
44+
this.octokit = await this.createOctokit(false);
5345
}
5446
}));
5547
}
5648

5749
async getOctokit(): Promise<Octokit.Octokit> {
58-
if (this.octokitAndToken) {
59-
return this.octokitAndToken.octokit;
50+
if (this.octokit) {
51+
return this.octokit;
6052
}
6153

62-
this.octokitAndToken = await this.createOctokit(true);
54+
this.octokit = await this.createOctokit(true);
6355
// octokit shouldn't be undefined, since we've set "createIfNone: true".
6456
// The following block is mainly here to prevent a compiler error.
65-
if (!this.octokitAndToken) {
66-
throw new Error('Did not initialize Octokit.');
67-
}
68-
return this.octokitAndToken.octokit;
69-
}
70-
71-
async getToken(): Promise<string> {
72-
if (this.octokitAndToken) {
73-
return this.octokitAndToken.token;
74-
}
75-
this.octokitAndToken = await this.createOctokit(true);
76-
if (!this.octokitAndToken) {
57+
if (!this.octokit) {
7758
throw new Error('Did not initialize Octokit.');
7859
}
79-
return this.octokitAndToken.token;
60+
return this.octokit;
8061
}
8162
}

extensions/ql-vscode/src/run-remote-query.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ export async function runRemoteQuery(cliServer: cli.CodeQLCliServer, credentials
112112

113113
async function runRemoteQueriesApiRequest(credentials: Credentials, ref: string, language: string, repositories: string[], query: string) {
114114
const octokit = await credentials.getOctokit();
115-
const token = await credentials.getToken();
116115

117116
try {
118117
await octokit.request(
@@ -125,7 +124,6 @@ async function runRemoteQueriesApiRequest(credentials: Credentials, ref: string,
125124
language: language,
126125
repositories: repositories,
127126
query: query,
128-
token: token,
129127
}
130128
}
131129
);

0 commit comments

Comments
 (0)