diff --git a/README.md b/README.md index ad9dd9a1..7d49f557 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Find all accounts and password for the `service` in the keychain. `service` - The string service name. -Yields an array of `{ account: 'foo', password: 'bar' }`. +Yields an array of `{ service: 'foo', account: 'bar', password: 'baz' }`. ### findPassword(service) diff --git a/keytar.d.ts b/keytar.d.ts index fd80c583..eea9cbee 100644 --- a/keytar.d.ts +++ b/keytar.d.ts @@ -48,4 +48,4 @@ export declare function findPassword(service: string): Promise; * * @returns A promise for the array of found credentials. */ -export declare function findCredentials(service: string): Promise>; +export declare function findCredentials(service: string): Promise>; diff --git a/spec/keytar-spec.js b/spec/keytar-spec.js index 53ba627a..22cd3ceb 100644 --- a/spec/keytar-spec.js +++ b/spec/keytar-spec.js @@ -161,7 +161,10 @@ describe("keytar", function() { return a.account.localeCompare(b.account) }) - assert.deepEqual([{account: account, password: password}, {account: account2, password: password2}], sorted) + assert.deepEqual([ + { service: service, account: account, password: password }, + { service: service, account: account2, password: password2 } + ], sorted) }); it('returns an empty array when no credentials are found', async function() { @@ -191,7 +194,10 @@ describe("keytar", function() { return a.account.localeCompare(b.account) }) - assert.deepEqual([{account: account2, password: password2}, {account: account, password: password}], sorted) + assert.deepEqual([ + { service: service, account: account2, password: password2 }, + { service: service, account: account, password: password } + ], sorted) }) afterEach(async function() { diff --git a/src/async.cc b/src/async.cc index 20dd9c3c..b3c147e2 100644 --- a/src/async.cc +++ b/src/async.cc @@ -200,16 +200,24 @@ void FindCredentialsWorker::OnOK() { keytar::Credentials cred = *it; Napi::Object obj = Napi::Object::New(env); + Napi::String service = Napi::String::New(env, + std::get<0>(cred).data(), + std::get<0>(cred).length()); + Napi::String account = Napi::String::New(env, - cred.first.data(), - cred.first.length()); + std::get<1>(cred).data(), + std::get<1>(cred).length()); Napi::String password = Napi::String::New(env, - cred.second.data(), - cred.second.length()); + std::get<2>(cred).data(), + std::get<2>(cred).length()); #ifndef _WIN32 #pragma GCC diagnostic ignored "-Wunused-result" +#endif + obj.Set("service", service); +#ifndef _WIN32 +#pragma GCC diagnostic ignored "-Wunused-result" #endif obj.Set("account", account); #ifndef _WIN32 diff --git a/src/credentials.h b/src/credentials.h index 99e071b1..5c8d9801 100644 --- a/src/credentials.h +++ b/src/credentials.h @@ -2,11 +2,11 @@ #define SRC_CREDENTIALS_H_ #include -#include +#include namespace keytar { -typedef std::pair Credentials; +typedef std::tuple Credentials; } diff --git a/src/keytar_mac.cc b/src/keytar_mac.cc index 457fa4c3..2e34d404 100644 --- a/src/keytar_mac.cc +++ b/src/keytar_mac.cc @@ -226,6 +226,7 @@ Credentials getCredentialsForItem(CFDictionaryRef item) { kCFStringEncodingUTF8); Credentials cred = Credentials( + CFStringToStdString(service), CFStringToStdString(account), CFStringToStdString(password)); CFRelease(password); diff --git a/src/keytar_posix.cc b/src/keytar_posix.cc index 3a5ba7ca..a3065c89 100644 --- a/src/keytar_posix.cc +++ b/src/keytar_posix.cc @@ -173,7 +173,7 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service, continue; } - credentials->push_back(Credentials(account, password)); + credentials->push_back(Credentials(service, account, password)); free(account); free(password); } diff --git a/src/keytar_win.cc b/src/keytar_win.cc index 4fa82b64..9401e5cd 100644 --- a/src/keytar_win.cc +++ b/src/keytar_win.cc @@ -256,7 +256,7 @@ KEYTAR_OP_RESULT FindCredentials(const std::string& service, cred->CredentialBlob), cred->CredentialBlobSize); - credentials->push_back(Credentials(login, password)); + credentials->push_back(Credentials(service, login, password)); } CredFree(creds);