Merge from vscode dbe62be3266ffb6772a7f3db0bf61d63f4aa7f65 (#9337)

This commit is contained in:
Anthony Dresser
2020-02-26 00:23:48 -08:00
committed by GitHub
parent d2892ff78b
commit 067fcc8dfb
42 changed files with 384 additions and 409 deletions

View File

@@ -10,6 +10,13 @@ import Logger from './common/logger';
export const onDidChangeSessions = new vscode.EventEmitter<void>();
interface SessionData {
id: string;
accountName: string;
scopes: string[];
accessToken: string;
}
export class GitHubAuthenticationProvider {
private _sessions: vscode.AuthenticationSession[] = [];
private _githubServer = new GitHubServer();
@@ -58,7 +65,15 @@ export class GitHubAuthenticationProvider {
const storedSessions = await keychain.getToken();
if (storedSessions) {
try {
return JSON.parse(storedSessions);
const sessionData: SessionData[] = JSON.parse(storedSessions);
return sessionData.map(session => {
return {
id: session.id,
accountName: session.accountName,
scopes: session.scopes,
accessToken: () => Promise.resolve(session.accessToken)
};
});
} catch (e) {
Logger.error(`Error reading sessions: ${e}`);
}
@@ -68,7 +83,17 @@ export class GitHubAuthenticationProvider {
}
private async storeSessions(): Promise<void> {
await keychain.setToken(JSON.stringify(this._sessions));
const sessionData: SessionData[] = await Promise.all(this._sessions.map(async session => {
const resolvedAccessToken = await session.accessToken();
return {
id: session.id,
accountName: session.accountName,
scopes: session.scopes,
accessToken: resolvedAccessToken
};
}));
await keychain.setToken(JSON.stringify(sessionData));
}
get sessions(): vscode.AuthenticationSession[] {