From 72248d47e18a1d5163e5bfe6df6a49743c0b2ee7 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Tue, 30 Mar 2021 20:40:33 +0200 Subject: [PATCH] Windows workaround for keyring issue. So there is an issue with keyring w.r.t. frozen installs (maybe also local). If you have pywin32 installed, it works fine locally. Take a note here, that a variant of this package, pywin32-ctypes, a rudimentary version of that package that works wholly within python, is already installed as its a dependency for keyring on windows. Due to an unknown reason, when running it fails to detect this, so some workaround is needed, _or_ the 'normal' pywin32 package should be installed. However, problems occurred when attempts where made to install pywin32 via cx_freeze. Then the actual workaround was encountered (https://github.com/jaraco/keyring/issues/468), which _should_ hopefully let use use the keyring on windows without needing the 'full' version of pywin32. CURA-7180 --- cura/OAuth2/KeyringAttribute.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cura/OAuth2/KeyringAttribute.py b/cura/OAuth2/KeyringAttribute.py index f717f83bef..1cc1424e8f 100644 --- a/cura/OAuth2/KeyringAttribute.py +++ b/cura/OAuth2/KeyringAttribute.py @@ -11,7 +11,15 @@ from UM.Logger import Logger if TYPE_CHECKING: from cura.OAuth2.Models import BaseModel -DONT_EVER_STORE = ["refresh_token"] +# Need to do some extra workarounds on windows: +import sys +from UM.Platform import Platform +if Platform.isWindows() and hasattr(sys, "frozen"): + from keyring.backends.Windows import WinVaultKeyring + keyring.set_keyring(WinVaultKeyring()) + +# Even if errors happen, we don't want this stored locally: +DONT_EVER_STORE_LOCALLY = ["refresh_token"] class KeyringAttribute: """ @@ -35,19 +43,19 @@ class KeyringAttribute: keyring.set_password("cura", self._keyring_name, value) except PasswordSetError: self._store_secure = False - if self._name not in DONT_EVER_STORE: + if self._name not in DONT_EVER_STORE_LOCALLY: setattr(instance, self._name, value) Logger.logException("w", "Keyring access denied") except NoKeyringError: self._store_secure = False - if self._name not in DONT_EVER_STORE: + if self._name not in DONT_EVER_STORE_LOCALLY: setattr(instance, self._name, value) Logger.logException("w", "No keyring backend present") except BaseException as e: # A BaseException can occur in Windows when the keyring attempts to write a token longer than 1024 # characters in the Windows Credentials Manager. self._store_secure = False - if self._name not in DONT_EVER_STORE: + if self._name not in DONT_EVER_STORE_LOCALLY: setattr(instance, self._name, value) Logger.log("w", "Keyring failed: {}".format(e)) else: