extensions - fully provide keytar API

This commit is contained in:
Benjamin Pasero
2019-08-28 15:08:51 +02:00
parent b05051e549
commit fa7eba4888
7 changed files with 33 additions and 11 deletions

View File

@@ -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);