Skip to content

Commit 3bd70b9

Browse files
committed
Merge branch 'release-1.25.0'
2 parents db74e80 + 1666d85 commit 3bd70b9

18 files changed

+636
-321
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
4+
title: '[Bug] '
5+
labels: ["untriaged", "needs attention"]
66
assignees: ''
77

88
---

.github/workflows/python-package.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
runs-on: ubuntu-latest # It switched to 22.04 shortly after 2022-Nov-8
2727
strategy:
2828
matrix:
29-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12-dev"]
29+
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
3030

3131
steps:
32-
- uses: actions/checkout@v2
32+
- uses: actions/checkout@v4
3333
- name: Set up Python ${{ matrix.python-version }}
34-
uses: actions/setup-python@v2
34+
uses: actions/setup-python@v4
3535
# It automatically takes care of pip cache, according to
3636
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#about-caching-workflow-dependencies
3737
with:
@@ -57,9 +57,9 @@ jobs:
5757
needs: ci
5858
runs-on: ubuntu-latest
5959
steps:
60-
- uses: actions/checkout@v2
60+
- uses: actions/checkout@v4
6161
- name: Set up Python 3.9
62-
uses: actions/setup-python@v2
62+
uses: actions/setup-python@v4
6363
with:
6464
python-version: 3.9
6565
- name: Install dependencies
@@ -97,9 +97,9 @@ jobs:
9797
)
9898
runs-on: ubuntu-latest
9999
steps:
100-
- uses: actions/checkout@v2
100+
- uses: actions/checkout@v4
101101
- name: Set up Python 3.9
102-
uses: actions/setup-python@v2
102+
uses: actions/setup-python@v4
103103
with:
104104
python-version: 3.9
105105
- name: Build a package for release

.readthedocs.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Set the version of Python and other tools you might need
9+
build:
10+
os: ubuntu-22.04
11+
tools:
12+
python: "3.12"
13+
14+
# Build documentation in the docs/ directory with Sphinx
15+
sphinx:
16+
configuration: docs/conf.py
17+
18+
# We recommend specifying your dependencies to enable reproducible builds:
19+
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
20+
python:
21+
install:
22+
- requirements: docs/requirements.txt

msal/__main__.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
66
Usage 1: Run it on the fly.
77
python -m msal
8+
Note: We choose to not define a console script to avoid name conflict.
89
910
Usage 2: Build an all-in-one executable file for bug bash.
1011
shiv -e msal.__main__._main -o msaltest-on-os-name.pyz .
11-
Note: We choose to not define a console script to avoid name conflict.
1212
"""
13-
import base64, getpass, json, logging, sys, msal
13+
import base64, getpass, json, logging, sys, os, atexit, msal
14+
15+
_token_cache_filename = "msal_cache.bin"
16+
global_cache = msal.SerializableTokenCache()
17+
atexit.register(lambda:
18+
open(_token_cache_filename, "w").write(global_cache.serialize())
19+
# Hint: The following optional line persists only when state changed
20+
if global_cache.has_state_changed else None
21+
)
1422

1523
_AZURE_CLI = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
1624
_VISUAL_STUDIO = "04f0c124-f2bc-4f59-8241-bf6df9866bbd"
@@ -66,7 +74,7 @@ def _select_account(app):
6674
if accounts:
6775
return _select_options(
6876
accounts,
69-
option_renderer=lambda a: a["username"],
77+
option_renderer=lambda a: "{}, came from {}".format(a["username"], a["account_source"]),
7078
header="Account(s) already signed in inside MSAL Python:",
7179
)
7280
else:
@@ -76,7 +84,7 @@ def _acquire_token_silent(app):
7684
"""acquire_token_silent() - with an account already signed into MSAL Python."""
7785
account = _select_account(app)
7886
if account:
79-
print_json(app.acquire_token_silent(
87+
print_json(app.acquire_token_silent_with_error(
8088
_input_scopes(),
8189
account=account,
8290
force_refresh=_input_boolean("Bypass MSAL Python's token cache?"),
@@ -107,6 +115,7 @@ def _acquire_token_interactive(app, scopes=None, data=None):
107115
enable_msa_passthrough=app.client_id in [ # Apps are expected to set this right
108116
_AZURE_CLI, _VISUAL_STUDIO,
109117
], # Here this test app mimics the setting for some known MSA-PT apps
118+
port=1234, # Hard coded for testing. Real app typically uses default value.
110119
prompt=prompt, login_hint=login_hint, data=data or {},
111120
)
112121
if login_hint and "id_token_claims" in result:
@@ -121,6 +130,15 @@ def _acquire_token_by_username_password(app):
121130
print_json(app.acquire_token_by_username_password(
122131
_input("username: "), getpass.getpass("password: "), scopes=_input_scopes()))
123132

133+
def _acquire_token_by_device_flow(app):
134+
"""acquire_token_by_device_flow() - Note that this one does not go through broker"""
135+
flow = app.initiate_device_flow(scopes=_input_scopes())
136+
print(flow["message"])
137+
sys.stdout.flush() # Some terminal needs this to ensure the message is shown
138+
input("After you completed the step above, press ENTER in this console to continue...")
139+
result = app.acquire_token_by_device_flow(flow) # By default it will block
140+
print_json(result)
141+
124142
_JWK1 = """{"kty":"RSA", "n":"2tNr73xwcj6lH7bqRZrFzgSLj7OeLfbn8216uOMDHuaZ6TEUBDN8Uz0ve8jAlKsP9CQFCSVoSNovdE-fs7c15MxEGHjDcNKLWonznximj8pDGZQjVdfK-7mG6P6z-lgVcLuYu5JcWU_PeEqIKg5llOaz-qeQ4LEDS4T1D2qWRGpAra4rJX1-kmrWmX_XIamq30C9EIO0gGuT4rc2hJBWQ-4-FnE1NXmy125wfT3NdotAJGq5lMIfhjfglDbJCwhc8Oe17ORjO3FsB5CLuBRpYmP7Nzn66lRY3Fe11Xz8AEBl3anKFSJcTvlMnFtu3EpD-eiaHfTgRBU7CztGQqVbiQ", "e":"AQAB"}"""
125143
_SSH_CERT_DATA = {"token_type": "ssh-cert", "key_id": "key1", "req_cnf": _JWK1}
126144
_SSH_CERT_SCOPE = ["https://pas.windows.net/CheckMyAccess/Linux/.default"]
@@ -181,6 +199,27 @@ def _exit(app):
181199

182200
def _main():
183201
print("Welcome to the Msal Python {} Tester (Experimental)\n".format(msal.__version__))
202+
cache_choice = _select_options([
203+
{
204+
"choice": "empty",
205+
"desc": "Start with an empty token cache. Suitable for one-off tests.",
206+
},
207+
{
208+
"choice": "reuse",
209+
"desc": "Reuse the previous token cache {} (if any) "
210+
"which was created during last test app exit. "
211+
"Useful for testing acquire_token_silent() repeatedly".format(
212+
_token_cache_filename),
213+
},
214+
],
215+
option_renderer=lambda o: o["desc"],
216+
header="What token cache state do you want to begin with?",
217+
accept_nonempty_string=False)
218+
if cache_choice["choice"] == "reuse" and os.path.exists(_token_cache_filename):
219+
try:
220+
global_cache.deserialize(open(_token_cache_filename, "r").read())
221+
except IOError:
222+
pass # Use empty token cache
184223
chosen_app = _select_options([
185224
{"client_id": _AZURE_CLI, "name": "Azure CLI (Correctly configured for MSA-PT)"},
186225
{"client_id": _VISUAL_STUDIO, "name": "Visual Studio (Correctly configured for MSA-PT)"},
@@ -189,9 +228,9 @@ def _main():
189228
option_renderer=lambda a: a["name"],
190229
header="Impersonate this app (or you can type in the client_id of your own app)",
191230
accept_nonempty_string=True)
192-
allow_broker = _input_boolean("Allow broker?")
231+
enable_broker = _input_boolean("Enable broker? It will error out later if your app has not registered some redirect URI")
193232
enable_debug_log = _input_boolean("Enable MSAL Python's DEBUG log?")
194-
enable_pii_log = _input_boolean("Enable PII in broker's log?") if allow_broker and enable_debug_log else False
233+
enable_pii_log = _input_boolean("Enable PII in broker's log?") if enable_broker and enable_debug_log else False
195234
app = msal.PublicClientApplication(
196235
chosen_app["client_id"] if isinstance(chosen_app, dict) else chosen_app,
197236
authority=_select_options([
@@ -204,8 +243,9 @@ def _main():
204243
header="Input authority (Note that MSA-PT apps would NOT use the /common authority)",
205244
accept_nonempty_string=True,
206245
),
207-
allow_broker=allow_broker,
246+
enable_broker_on_windows=enable_broker,
208247
enable_pii_log=enable_pii_log,
248+
token_cache=global_cache,
209249
)
210250
if enable_debug_log:
211251
logging.basicConfig(level=logging.DEBUG)
@@ -214,6 +254,7 @@ def _main():
214254
_acquire_token_silent,
215255
_acquire_token_interactive,
216256
_acquire_token_by_username_password,
257+
_acquire_token_by_device_flow,
217258
_acquire_ssh_cert_silently,
218259
_acquire_ssh_cert_interactive,
219260
_acquire_pop_token_interactive,

0 commit comments

Comments
 (0)