|
1 | | -import sys |
2 | 1 | import logging |
3 | 2 | import json |
4 | 3 |
|
5 | | -from msal_extensions import * |
| 4 | +from msal_extensions import build_encrypted_persistence, FilePersistence, CrossPlatLock |
6 | 5 |
|
7 | 6 |
|
8 | 7 | def build_persistence(location, fallback_to_plaintext=False): |
9 | 8 | """Build a suitable persistence instance based your current OS""" |
10 | | - if sys.platform.startswith('win'): |
11 | | - return FilePersistenceWithDataProtection(location) |
12 | | - if sys.platform.startswith('darwin'): |
13 | | - return KeychainPersistence(location) |
14 | | - if sys.platform.startswith('linux'): |
15 | | - try: |
16 | | - return LibsecretPersistence( |
17 | | - # By using same location as the fall back option below, |
18 | | - # this would override the unencrypted data stored by the |
19 | | - # fall back option. It is probably OK, or even desirable |
20 | | - # (in order to aggressively wipe out plain-text persisted data), |
21 | | - # unless there would frequently be a desktop session and |
22 | | - # a remote ssh session being active simultaneously. |
23 | | - location, |
24 | | - ) |
25 | | - except: # pylint: disable=bare-except |
26 | | - if not fallback_to_plaintext: |
27 | | - raise |
28 | | - logging.warning("Encryption unavailable. Opting in to plain text.") |
29 | | - return FilePersistence(location) |
| 9 | + # Note: This sample stores both encrypted persistence and plaintext persistence |
| 10 | + # into same location, therefore their data would likely override with each other. |
| 11 | + try: |
| 12 | + return build_encrypted_persistence(location) |
| 13 | + except: # pylint: disable=bare-except |
| 14 | + # Known issue: Currently, only Linux |
| 15 | + if not fallback_to_plaintext: |
| 16 | + raise |
| 17 | + logging.warning("Encryption unavailable. Opting in to plain text.") |
| 18 | + return FilePersistence(location) |
30 | 19 |
|
31 | 20 | persistence = build_persistence("storage.bin", fallback_to_plaintext=False) |
32 | 21 | print("Type of persistence: {}".format(persistence.__class__.__name__)) |
|
0 commit comments