|
2 | 2 | # Copyright (c) Microsoft Corporation.
|
3 | 3 | # Licensed under the MIT License.
|
4 | 4 | # ------------------------------------
|
| 5 | +import logging |
5 | 6 | import os
|
6 | 7 | import sys
|
7 | 8 | from typing import TYPE_CHECKING
|
8 | 9 |
|
| 10 | +import six |
| 11 | + |
9 | 12 | if TYPE_CHECKING:
|
10 | 13 | from typing import Any
|
11 | 14 | import msal_extensions
|
12 | 15 |
|
| 16 | +_LOGGER = logging.getLogger(__name__) |
| 17 | + |
13 | 18 |
|
14 | 19 | class TokenCachePersistenceOptions(object):
|
15 | 20 | """Options for persistent token caching.
|
@@ -86,12 +91,16 @@ def _get_persistence(allow_unencrypted, account_name, cache_name):
|
86 | 91 | return msal_extensions.LibsecretPersistence(
|
87 | 92 | file_path, cache_name, {"MsalClientID": "Microsoft.Developer.IdentityService"}, label=account_name
|
88 | 93 | )
|
89 |
| - except ImportError: |
| 94 | + except Exception as ex: # pylint:disable=broad-except |
| 95 | + _LOGGER.debug('msal-extensions is unable to encrypt a persistent cache: "%s"', ex, exc_info=True) |
90 | 96 | if not allow_unencrypted:
|
91 |
| - raise ValueError( |
92 |
| - "PyGObject is required to encrypt the persistent cache. Please install that library or " |
93 |
| - + 'specify "allow_unencrypted_storage=True" to store the cache without encryption.' |
| 97 | + error = ValueError( |
| 98 | + "Cache encryption is impossible because libsecret dependencies are not installed or are unusable," |
| 99 | + + " for example because no display is available (as in an SSH session). The chained exception has" |
| 100 | + + ' more information. Specify "allow_unencrypted_storage=True" to store the cache unencrypted' |
| 101 | + + " instead of raising this exception." |
94 | 102 | )
|
95 |
| - return msal_extensions.FilePersistence(file_path) |
| 103 | + six.raise_from(error, ex) |
| 104 | + return msal_extensions.FilePersistence(file_path) |
96 | 105 |
|
97 | 106 | raise NotImplementedError("A persistent cache is not available in this environment.")
|
0 commit comments