Skip to content

Commit db005ca

Browse files
committed
Detect unsupported Portal so that AzCLI could fallback
1 parent ffea5ef commit db005ca

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

msal/cloudshell.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ def _acquire_token(http_client, scopes, client_id=None, data=None):
5353
"error_description": cs_error.get("message"),
5454
}.items() if v}
5555
imds_payload = json.loads(resp.text)
56+
BEARER = "Bearer"
5657
oauth2_response = {
5758
"access_token": imds_payload["access_token"],
5859
"expires_in": int(imds_payload["expires_in"]),
59-
"token_type": imds_payload.get("token_type", "Bearer"),
60+
"token_type": imds_payload.get("token_type", BEARER),
6061
}
62+
expected_token_type = (data or {}).get("token_type", BEARER)
63+
if oauth2_response["token_type"] != expected_token_type:
64+
return { # Generate a normal error (rather than an intrusive exception)
65+
"error": "broker_error",
66+
"error_description": "token_type {} is not supported by this version of Azure Portal".format(
67+
expected_token_type),
68+
}
6169
parts = imds_payload["access_token"].split(".")
6270

6371
# The following default values are useful in SSH Cert scenario

0 commit comments

Comments
 (0)