From 65bcbd14140970abfdd8d5324d4dbabee3658706 Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Tue, 9 Jul 2019 11:41:30 -0700 Subject: [PATCH 1/6] Making cache_location mandatory Minimize the chance of irrelative apps sharing tokens by removing the default centralized location. Alternatively, we could keep the default behavior but use a per-app location such as os.path.join(sys.argv[0] + ".cache"). But we choose to NOT do this flavor this time. It's always easier to add surface area later than to take it away. --- msal_extensions/token_cache.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/msal_extensions/token_cache.py b/msal_extensions/token_cache.py index 878ebca..fce54b1 100644 --- a/msal_extensions/token_cache.py +++ b/msal_extensions/token_cache.py @@ -33,10 +33,7 @@ def _mkdir_p(path): class FileTokenCache(msal.SerializableTokenCache): """Implements basic unprotected SerializableTokenCache to a plain-text file.""" def __init__(self, - cache_location=os.path.join( - os.getenv('LOCALAPPDATA', os.path.expanduser('~')), - '.IdentityService', - 'msal.cache'), + cache_location, lock_location=None): super(FileTokenCache, self).__init__() self._cache_location = cache_location @@ -121,19 +118,19 @@ def find(self, credential_type, **kwargs): # pylint: disable=arguments-differ class UnencryptedTokenCache(FileTokenCache): """An unprotected token cache to default to when no-platform specific option is available.""" - def __init__(self, **kwargs): + def __init__(self, cache_location, **kwargs): warnings.warn("You are using an unprotected token cache, " "because an encrypted option is not available for {}".format(sys.platform), RuntimeWarning) - super(UnencryptedTokenCache, self).__init__(**kwargs) + super(UnencryptedTokenCache, self).__init__(cache_location, **kwargs) class WindowsTokenCache(FileTokenCache): """A SerializableTokenCache implementation which uses Win32 encryption APIs to protect your tokens. """ - def __init__(self, entropy='', **kwargs): - super(WindowsTokenCache, self).__init__(**kwargs) + def __init__(self, cache_location, entropy='', **kwargs): + super(WindowsTokenCache, self).__init__(cache_location, **kwargs) self._dp_agent = WindowsDataProtectionAgent(entropy=entropy) def _write(self, contents): @@ -152,10 +149,11 @@ class OSXTokenCache(FileTokenCache): """ def __init__(self, + cache_location, service_name='Microsoft.Developer.IdentityService', account_name='MSALCache', **kwargs): - super(OSXTokenCache, self).__init__(**kwargs) + super(OSXTokenCache, self).__init__(cache_location, **kwargs) self._service_name = service_name self._account_name = account_name From f09a8f645a5d1e9f1035aa4e8d467ef1ac52b753 Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 10 Jul 2019 11:06:22 -0700 Subject: [PATCH 2/6] Experimental See if we can bypass the currently-failing OSX environment --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 96b68fd..58d4431 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ matrix: - name: "Python 3.7 on macOS" env: TOXENV=py37 os: osx + if: branch = mandatory_cache_location osx_image: xcode10.2 language: shell - name: "Python 2.7 on Windows" From 083e626131cd49be6abbae07e1f601945280a36e Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 10 Jul 2019 11:13:20 -0700 Subject: [PATCH 3/6] More experiment for the LICENSE error on OSX --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ce287c8..3eec425 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ 'Development Status :: 2 - Pre-Alpha', ], install_requires=[ - 'msal~=0.4', + 'msal=0.4.1', # 'msal~=0.4', 'portalocker~=1.0', ], tests_require=['pytest'], From 80557845d11075dc9f3a884c6fa3d75199f7c842 Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 10 Jul 2019 11:20:46 -0700 Subject: [PATCH 4/6] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 3eec425..0fa63b4 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ 'Development Status :: 2 - Pre-Alpha', ], install_requires=[ - 'msal=0.4.1', # 'msal~=0.4', + 'msal==0.4.1', # 'msal~=0.4', 'portalocker~=1.0', ], tests_require=['pytest'], From 9da8eb8686ceb2a00b08369fafaeacb44bd1fdbf Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 10 Jul 2019 15:19:11 -0700 Subject: [PATCH 5/6] Rollback unnecessary changes as they've been fixed at upstream --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0fa63b4..ce287c8 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ 'Development Status :: 2 - Pre-Alpha', ], install_requires=[ - 'msal==0.4.1', # 'msal~=0.4', + 'msal~=0.4', 'portalocker~=1.0', ], tests_require=['pytest'], From 2c534ee17b151c96e09e56d1644c534336147cda Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Wed, 10 Jul 2019 15:21:11 -0700 Subject: [PATCH 6/6] Rollback unnecessary changes as they've been fixed at upstream --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 58d4431..96b68fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,6 @@ matrix: - name: "Python 3.7 on macOS" env: TOXENV=py37 os: osx - if: branch = mandatory_cache_location osx_image: xcode10.2 language: shell - name: "Python 2.7 on Windows"