Skip to content

Commit dfeb811

Browse files
committed
Merge remote-tracking branch 'origin/dev' into test/release-pipeline-preview
2 parents cfbd078 + 895b581 commit dfeb811

3 files changed

Lines changed: 29 additions & 31 deletions

File tree

msal/broker.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ class TokenTypeError(ValueError):
4545
pass
4646

4747

48-
_redirect_uri_on_mac = "msauth.com.msauth.unsignedapp://auth" # Note:
48+
_default_redirect_uri_on_mac = "msauth.com.msauth.unsignedapp://auth" # Note:
4949
# On Mac, the native Python has a team_id which links to bundle id
5050
# com.apple.python3 however it won't give Python scripts better security.
5151
# Besides, the homebrew-installed Pythons have no team_id
5252
# so they have to use a generic placeholder anyway.
5353
# The v-team chose to combine two situations into using same placeholder.
5454

55+
_default_redirect_uri = "https://login.microsoftonline.com/common/oauth2/nativeclient"
56+
# Linux Java Broker requires a non-empty valid redirect_uri.
57+
# On Windows, WAM does not currently use this default redirect_uri,
58+
# but MSAL.cpp still requires it to be non-empty and valid.
5559

5660
def _convert_error(error, client_id):
5761
context = error.get_context() # Available since pymsalruntime 0.0.4
@@ -63,8 +67,7 @@ def _convert_error(error, client_id):
6367
"""MsalRuntime needs the current app to register these redirect_uri
6468
(1) ms-appx-web://Microsoft.AAD.BrokerPlugin/{}
6569
(2) {}
66-
(3) https://login.microsoftonline.com/common/oauth2/nativeclient""".format(
67-
client_id, _redirect_uri_on_mac))
70+
(3) {}""".format(client_id, _default_redirect_uri_on_mac, _default_redirect_uri))
6871
# OTOH, AAD would emit other errors when other error handling branch was hit first,
6972
# so, the AADSTS50011/RedirectUriError is not guaranteed to happen.
7073
return {
@@ -145,20 +148,19 @@ def _build_msal_runtime_auth_params(client_id, authority):
145148
params.set_additional_parameter("msal_client_ver", __version__)
146149
return params
147150

148-
def _set_redirect_uri_for_linux(params):
149-
if sys.platform == "linux":
150-
# This is required by Linux Java Broker to set a non-empty valid redirect_uri
151-
params.set_redirect_uri(
152-
"https://login.microsoftonline.com/common/oauth2/nativeclient"
153-
)
151+
def _set_redirect_uri(params):
152+
if sys.platform == "darwin":
153+
params.set_redirect_uri(_default_redirect_uri_on_mac)
154+
else:
155+
params.set_redirect_uri(_default_redirect_uri)
154156

155157
def _signin_silently(
156158
authority, client_id, scopes, correlation_id=None, claims=None,
157159
enable_msa_pt=False,
158160
auth_scheme=None,
159161
**kwargs):
160162
params = _build_msal_runtime_auth_params(client_id, authority)
161-
_set_redirect_uri_for_linux(params)
163+
_set_redirect_uri(params)
162164
params.set_requested_scopes(scopes)
163165
if claims:
164166
params.set_decoded_claims(claims)
@@ -193,12 +195,7 @@ def _signin_interactively(
193195
**kwargs):
194196
params = _build_msal_runtime_auth_params(client_id, authority)
195197
params.set_requested_scopes(scopes)
196-
params.set_redirect_uri(
197-
_redirect_uri_on_mac if sys.platform == "darwin" else
198-
"https://login.microsoftonline.com/common/oauth2/nativeclient"
199-
# This default redirect_uri value is not currently used by WAM
200-
# but it is required by the MSAL.cpp to be set to a non-empty valid URI.
201-
)
198+
_set_redirect_uri(params)
202199
if prompt:
203200
if prompt == "select_account":
204201
if login_hint:
@@ -248,7 +245,7 @@ def _acquire_token_silently(
248245
if account is None:
249246
return
250247
params = _build_msal_runtime_auth_params(client_id, authority)
251-
_set_redirect_uri_for_linux(params)
248+
_set_redirect_uri(params)
252249
params.set_requested_scopes(scopes)
253250
if claims:
254251
params.set_decoded_claims(claims)

tests/test_cryptography.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class CryptographyTestCase(TestCase):
3535

3636
def test_should_be_run_with_latest_version_of_cryptography(self):
3737
import cryptography
38-
self.assertEqual(
39-
cryptography.__version__, latest_cryptography_version,
40-
"We are using cryptography {} but we should test with latest {} instead. "
41-
"Run 'pip install -U cryptography'.".format(
42-
cryptography.__version__, latest_cryptography_version))
38+
if cryptography.__version__ != latest_cryptography_version:
39+
warnings.warn(
40+
"We are using cryptography {} but we should test with latest {} instead. "
41+
"Run 'pip install -U cryptography'.".format(
42+
cryptography.__version__, latest_cryptography_version))
4343

4444
def test_latest_cryptography_should_support_our_usage_without_warnings(self):
4545
passphrase_bytes = _str2bytes("password")
@@ -54,10 +54,11 @@ def test_latest_cryptography_should_support_our_usage_without_warnings(self):
5454

5555
def test_ceiling_should_be_latest_cryptography_version_plus_three(self):
5656
expected_ceiling = int(latest_cryptography_version.split(".")[0]) + 3
57-
self.assertEqual(
58-
expected_ceiling, get_current_ceiling(),
59-
"Test passed with latest cryptography, so we shall bump ceiling to N+3={}, "
60-
"based on their latest deprecation policy "
61-
"https://cryptography.io/en/latest/api-stability/#deprecation".format(
62-
expected_ceiling))
57+
current_ceiling = get_current_ceiling()
58+
if expected_ceiling != current_ceiling:
59+
warnings.warn(
60+
"Test passed with latest cryptography, so we shall bump ceiling to N+3={}, "
61+
"based on their latest deprecation policy "
62+
"https://cryptography.io/en/latest/api-stability/#deprecation".format(
63+
expected_ceiling))
6364

tests/test_fmi_e2e.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
logging.basicConfig(level=logging.DEBUG if "-v" in sys.argv else logging.INFO)
2222

2323
# Test configuration
24-
_FMI_TENANT_ID = "f645ad92-e38d-4d1a-b510-d1b09a74a8ca"
25-
_FMI_CLIENT_ID = "4df2cbbb-8612-49c1-87c8-f334d6d065ad"
26-
_FMI_SCOPE = "3091264c-7afb-45d4-b527-39737ee86187/.default"
24+
_FMI_TENANT_ID = "10c419d4-4a50-45b2-aa4e-919fb84df24f"
25+
_FMI_CLIENT_ID = "3bf56293-fbb5-42bd-a407-248ba7431a8c"
26+
_FMI_SCOPE = "aa464f73-2868-4f67-b0e7-fc2f749e757f/.default"
2727
_FMI_PATH = "SomeFmiPath/FmiCredentialPath"
2828
_FMI_CLIENT_ID_URN = "urn:microsoft:identity:fmi"
2929
_FMI_SCOPE_FOR_RMA = "api://AzureFMITokenExchange/.default"

0 commit comments

Comments
 (0)