Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def _get_token_by_auth_code(self, scopes, **kwargs):
scopes = list(scopes) # type: ignore
request_state = str(uuid.uuid4())
app = self._get_app()
auth_url = app.get_authorization_request_url(scopes, redirect_uri=redirect_uri, state=request_state, **kwargs)
auth_url = app.get_authorization_request_url(
scopes, redirect_uri=redirect_uri, state=request_state, prompt="select_account", **kwargs
)

# open browser to that url
if not webbrowser.open(auth_url):
Expand Down
14 changes: 12 additions & 2 deletions sdk/identity/azure-identity/tests/test_interactive_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.identity import InteractiveBrowserCredential
from azure.identity._internal import AuthCodeRedirectServer
import pytest
from six.moves import urllib
from six.moves import urllib, urllib_parse

from helpers import build_aad_response, mock_response, Request, validating_transport

Expand All @@ -23,7 +23,7 @@

@patch("azure.identity._credentials.browser.webbrowser.open")
def test_interactive_credential(mock_open):
mock_open.return_value = True # the real webbrowser.open returns a bool
mock_open.side_effect = _validate_auth_request_url
oauth_state = "state"
client_id = "client-id"
expected_refresh_token = "refresh-token"
Expand Down Expand Up @@ -171,3 +171,13 @@ def test_no_browser():
)
with pytest.raises(ClientAuthenticationError, match=r".*browser.*"):
credential.get_token("scope")


def _validate_auth_request_url(url):
parsed_url = urllib_parse.urlparse(url)
params = urllib_parse.parse_qs(parsed_url.query)
assert params.get("prompt") == ["select_account"], "Auth code request doesn't specify 'prompt=select_account'."

# when used as a Mock's side_effect, this method's return value is the Mock's return value
# (the real webbrowser.open returns a bool)
return True