Files
vscode/extensions/github-authentication/src/common/keychain.ts
Tyler James Leonhardt 5134662139 Remove CredentialsService & keytar (#192224)
* Remove CredentialsService & keytar

ref https://github.com/microsoft/vscode/issues/115215
fixes https://github.com/microsoft/vscode/issues/143395

* compile

* remove imports

* rip the bandaid
2023-09-05 17:47:30 -07:00

49 lines
1.4 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { Log } from './logger';
export class Keychain {
constructor(
private readonly context: vscode.ExtensionContext,
private readonly serviceId: string,
private readonly Logger: Log
) { }
async setToken(token: string): Promise<void> {
try {
return await this.context.secrets.store(this.serviceId, token);
} catch (e) {
// Ignore
this.Logger.error(`Setting token failed: ${e}`);
}
}
async getToken(): Promise<string | null | undefined> {
try {
const secret = await this.context.secrets.get(this.serviceId);
if (secret && secret !== '[]') {
this.Logger.trace('Token acquired from secret storage.');
}
return secret;
} catch (e) {
// Ignore
this.Logger.error(`Getting token failed: ${e}`);
return Promise.resolve(undefined);
}
}
async deleteToken(): Promise<void> {
try {
return await this.context.secrets.delete(this.serviceId);
} catch (e) {
// Ignore
this.Logger.error(`Deleting token failed: ${e}`);
return Promise.resolve(undefined);
}
}
}