I am writing a language server that sometimes needs to access data from a GitHub repository. I am following this sample to obtain GitHub authentication. The sample is based on client-side code, so I'm wondering how I would provide the authenticated GitHub session to the language server code. I know I can send messages from client to server, but I would need to be able to keep the session(s) in-mem for use during diagnostics, completions, doc symbols, etc. Is there a way to track the sessions in the server?
Asked
Active
Viewed 96 times
1 Answers
0
Looking at the sample code, an authentication token is obtained in the setOctokit()
method in src/credentials.ts
:
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: false }); if (session) { this.octokit = new Octokit.Octokit({ auth: session.accessToken }); return; }
That should mean it is possible to do the following:
- The client runs
const session = await vscode.authentication.getSession(GITHUB_AUTH_PROVIDER_ID, SCOPES, { createIfNone: false });
- The client sends
session.accessToken
to the server - The server can then initialize Octokit with this token to log into the GitHub API

virchau13
- 1,175
- 7
- 19
-
The problem is that not only do I need to send it to the server, I need to be able to track it in the server so it's available when needed during all the different operations the server performs. I'm not sure how I can do that on the server reliably. I can't find anything on session states in an LSP server. – GabeV Oct 17 '22 at 16:21