mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-03 23:06:49 +01:00
extensions - fully provide keytar API
This commit is contained in:
@@ -13,6 +13,7 @@ export interface ICredentialsProvider {
|
||||
setPassword(service: string, account: string, password: string): Promise<void>;
|
||||
deletePassword(service: string, account: string): Promise<boolean>;
|
||||
findPassword(service: string): Promise<string | null>;
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string }>>;
|
||||
}
|
||||
|
||||
export class BrowserCredentialsService implements ICredentialsService {
|
||||
@@ -29,21 +30,25 @@ export class BrowserCredentialsService implements ICredentialsService {
|
||||
}
|
||||
}
|
||||
|
||||
async getPassword(service: string, account: string): Promise<string | null> {
|
||||
getPassword(service: string, account: string): Promise<string | null> {
|
||||
return this.credentialsProvider.getPassword(service, account);
|
||||
}
|
||||
|
||||
async setPassword(service: string, account: string, password: string): Promise<void> {
|
||||
setPassword(service: string, account: string, password: string): Promise<void> {
|
||||
return this.credentialsProvider.setPassword(service, account, password);
|
||||
}
|
||||
|
||||
async deletePassword(service: string, account: string): Promise<boolean> {
|
||||
deletePassword(service: string, account: string): Promise<boolean> {
|
||||
return this.credentialsProvider.deletePassword(service, account);
|
||||
}
|
||||
|
||||
async findPassword(service: string): Promise<string | null> {
|
||||
findPassword(service: string): Promise<string | null> {
|
||||
return this.credentialsProvider.findPassword(service);
|
||||
}
|
||||
|
||||
findCredentials(service: string): Promise<Array<{ account: string, password: string }>> {
|
||||
return this.credentialsProvider.findCredentials(service);
|
||||
}
|
||||
}
|
||||
|
||||
interface ICredential {
|
||||
@@ -127,6 +132,12 @@ class LocalStorageCredentialsProvider implements ICredentialsProvider {
|
||||
async findPassword(service: string): Promise<string | null> {
|
||||
return this.doGetPassword(service);
|
||||
}
|
||||
|
||||
async findCredentials(service: string): Promise<Array<{ account: string, password: string }>> {
|
||||
return this.credentials
|
||||
.filter(credential => credential.service === service)
|
||||
.map(({ account, password }) => ({ account, password }));
|
||||
}
|
||||
}
|
||||
|
||||
registerSingleton(ICredentialsService, BrowserCredentialsService, true);
|
||||
|
||||
Reference in New Issue
Block a user