-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add login_hint argument to InteractiveBrowserCredential (#19229)
- Loading branch information
Showing
3 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,33 @@ def test_claims_challenge(): | |
assert kwargs["claims_challenge"] == expected_claims | ||
|
||
|
||
def test_login_hint(): | ||
expected_username = "[email protected]" | ||
auth_code_response = {"code": "authorization-code", "state": ["..."]} | ||
server_class = Mock(return_value=Mock(wait_for_redirect=lambda: auth_code_response)) | ||
transport = Mock(send=Mock(side_effect=Exception("this test mocks MSAL, so no request should be sent"))) | ||
|
||
msal_acquire_token_result = dict( | ||
build_aad_response(access_token="**", id_token=build_id_token()), | ||
id_token_claims=id_token_claims("issuer", "subject", "audience", upn="upn"), | ||
) | ||
mock_msal_app = Mock( | ||
acquire_token_by_auth_code_flow=Mock(return_value=msal_acquire_token_result), | ||
initiate_auth_code_flow=Mock(return_value={"auth_uri": "http://localhost"}), | ||
) | ||
|
||
credential = InteractiveBrowserCredential( | ||
_server_class=server_class, transport=transport, login_hint=expected_username | ||
) | ||
with patch("msal.PublicClientApplication", Mock(return_value=mock_msal_app)): | ||
with patch(WEBBROWSER_OPEN, lambda _: True): | ||
credential.authenticate(scopes=["scope"]) | ||
|
||
assert mock_msal_app.initiate_auth_code_flow.call_count == 1 | ||
_, kwargs = mock_msal_app.initiate_auth_code_flow.call_args | ||
assert kwargs["login_hint"] == expected_username | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"uname,is_wsl", | ||
( | ||
|