diff --git a/keyring/backends/macOS/__init__.py b/keyring/backends/macOS/__init__.py index 18ec1ec4..334db360 100644 --- a/keyring/backends/macOS/__init__.py +++ b/keyring/backends/macOS/__init__.py @@ -57,9 +57,6 @@ def set_password(self, service, username, password): @warn_keychain def get_password(self, service, username): - if username is None: - username = '' - try: return api.find_generic_password(self.keychain, service, username) except api.NotFound: diff --git a/keyring/backends/macOS/api.py b/keyring/backends/macOS/api.py index 7cea4a04..b4e622ee 100644 --- a/keyring/backends/macOS/api.py +++ b/keyring/backends/macOS/api.py @@ -140,11 +140,13 @@ class SecAuthFailure(Error): def find_generic_password(kc_name, service, username, not_found_ok=False): + username_kwarg = {'kSecAttrAccount': username} if username is not None else {} + q = create_query( kSecClass=k_('kSecClassGenericPassword'), kSecMatchLimit=k_('kSecMatchLimitOne'), kSecAttrService=service, - kSecAttrAccount=username, + **username_kwarg, kSecReturnData=True, )