remove keytar fallback in keychain and add a ton more logging to microsoft auth. ref #133201

This commit is contained in:
Tyler Leonhardt
2021-10-25 11:16:37 -07:00
parent 7fd7b8f661
commit 4d496f61bc
6 changed files with 77 additions and 147 deletions

View File

@@ -5,29 +5,12 @@
// keytar depends on a native module shipped in vscode, so this is
// how we load it
import type * as keytarType from 'keytar';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { Log } from './logger';
const localize = nls.loadMessageBundle();
function getKeytar(): Keytar | undefined {
try {
return require('keytar');
} catch (err) {
console.log(err);
}
return undefined;
}
export type Keytar = {
getPassword: typeof keytarType['getPassword'];
setPassword: typeof keytarType['setPassword'];
deletePassword: typeof keytarType['deletePassword'];
};
export class Keychain {
constructor(
private readonly context: vscode.ExtensionContext,
@@ -72,25 +55,4 @@ export class Keychain {
return Promise.resolve(undefined);
}
}
async tryMigrate(): Promise<string | null | undefined> {
try {
const keytar = getKeytar();
if (!keytar) {
throw new Error('keytar unavailable');
}
const oldValue = await keytar.getPassword(`${vscode.env.uriScheme}-github.login`, 'account');
if (oldValue) {
this.Logger.trace('Attempting to migrate from keytar to secret store...');
await this.setToken(oldValue);
await keytar.deletePassword(`${vscode.env.uriScheme}-github.login`, 'account');
}
return oldValue;
} catch (_) {
// Ignore
return Promise.resolve(undefined);
}
}
}

View File

@@ -117,7 +117,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
let sessionData: SessionData[];
try {
this._logger.info('Reading sessions from keychain...');
const storedSessions = await this._keychain.getToken() || await this._keychain.tryMigrate();
const storedSessions = await this._keychain.getToken();
if (!storedSessions) {
return [];
}