You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 0.2.0 the simple TokenCache interface was replaced by newer API that now requires the user to write some code along these lines:
defbuild_persistence(location, fallback_to_plaintext=False):
"""Build a suitable persistence instance based your current OS"""ifsys.platform.startswith('win'):
returnFilePersistenceWithDataProtection(location)
ifsys.platform.startswith('darwin'):
returnKeychainPersistence(location, "my_service_name", "my_account_name")
ifsys.platform.startswith('linux'):
try:
returnLibsecretPersistence(
location,
schema_name="my_schema_name",
attributes={"my_attr1": "foo", "my_attr2": "bar"},
)
except: # pylint: disable=bare-exceptifnotfallback_to_plaintext:
raiselogging.exception("Encryption unavailable. Opting in to plain text.")
returnFilePersistence(location)
cache=PersistedTokenCache(build_persistence(...))
(That's taken from the README, of course.)
Is there a reason why this logic needs to be reproduced in all user code that doesn't have more particular requirements? Or, conversely, are there many situation where this wouldn't be good enough?
If not, couldn't the library provide a get_default_persistence(location) method, that contains something along the lines of the above? I would be happy to raise a PR for this.
Side note: we only recently noticed and updated our code to sync with this, since DeprecationWarning doesn't surface by default and you only get something more visible on Linux, where a RuntimeWarning is issued about the unprotected cache you're getting from the legacy TokenCache interface.
Thanks, Morgan Parry (@mparry), you raise a good point on the usability. I do not currently have a definite answer. Here is the background behind that change.
Up to MSAL Extensions version 0.1.3, the parameters for macOS's key chain service_name and account_name were indeed predefined with a hardcoded default value. It might not be obvious, but those 2 parameters decide where your encrypted data is actually stored in on macOS. Imagine 2 unrelated apps using MSAL Extensions 0.1.3 on the same macOS machine, their encrypted data would be saved into same logical namespace. That might not feel right, but it was at least functional, because MSAL Extensions 0.1.3 API was TokenCache, which was only used by MSAL's token cache, and all MSAL token cache has compatible data schema.
Activity
mparry commentedon Apr 14, 2021
Side note: we only recently noticed and updated our code to sync with this, since
DeprecationWarningdoesn't surface by default and you only get something more visible on Linux, where aRuntimeWarningis issued about the unprotected cache you're getting from the legacyTokenCacheinterface.rayluo commentedon Apr 14, 2021
Thanks, Morgan Parry (@mparry), you raise a good point on the usability. I do not currently have a definite answer. Here is the background behind that change.
service_nameandaccount_namewere indeed predefined with a hardcoded default value. It might not be obvious, but those 2 parameters decide where your encrypted data is actually stored in on macOS. Imagine 2 unrelated apps using MSAL Extensions 0.1.3 on the same macOS machine, their encrypted data would be saved into same logical namespace. That might not feel right, but it was at least functional, because MSAL Extensions 0.1.3 API wasTokenCache, which was only used by MSAL's token cache, and all MSAL token cache has compatible data schema.service_nameandaccount_namebecome required parameter in the persistence layer, to help preventing unrelated data being stored in same place and overwriting each other.At that time we experimented a helper combining those lower level parameters, but that did not actually encapsulate those details, and our friend @chlowell found it difficult to use, so it was changed to the 0.2.0 way you see today.
service_name,account_name, etc. from the required parameterlocation?We are open for PR contribution. Due to the cross-platform nature of this library, all changes need to be tested from all supported platforms.