Skip to content

Commit 2010ae7

Browse files
committed
Finalize the design
1 parent 04c18d8 commit 2010ae7

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

msal/application.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ def get_accounts(self, username=None):
982982
# In Cloud Shell, user already signed in w/ an account [email protected]
983983
# We pretend we have that account, for acquire_token_silent() to work.
984984
# Note: If user calls acquire_token_by_xyz() with same account later,
985-
# the get_accounts() would return multiple accounts to calling app,
985+
# the get_accounts(username=None) would return multiple accounts,
986986
# with different usernames: [email protected] and CURRENT_USER.
987987
accounts.insert(0, cloud_shell_pseudo_account)
988988
# Does not further filter by existing RTs here. It probably won't matter.
@@ -1149,20 +1149,7 @@ def acquire_token_silent_with_error(
11491149
assert isinstance(scopes, list), "Invalid parameter type"
11501150
self._validate_ssh_cert_input_data(kwargs.get("data", {}))
11511151

1152-
# TODO: TBD
1153-
# Currently, the following implementation activates Cloud Shell (CS) code path
1154-
# when a pseudo account was specified.
1155-
# But when/if the user signs in explicitly (such as "az login") with SAME account,
1156-
# to obtain tokens with scope(s) not supported by Cloud Shell's IMDS,
1157-
# the user would end up with one real account and still one pseudo account,
1158-
# both with same username.
1159-
# It would become unrealistic for end user to reason why
1160-
# the pseudo "default user" account would go one code path,
1161-
# and the real account would go another.
1162-
# I will probably refactor to automatically group Cloud Shell's default account
1163-
# and the real account into one, if they have same username.
1164-
# And then, acquire_token_silent() will always try real account if RT is available,
1165-
# and fallback to the Cloud Shell code path.
1152+
# The special code path only for _CLOUD_SHELL_USER
11661153
if account and account.get("home_account_id") == _CLOUD_SHELL_USER:
11671154
# Since we don't currently store cloud shell tokens in MSAL's cache,
11681155
# we can have a shortcut here, and semantically bypass all those

msal/cloudshell.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ def _scope_to_resource(scope):
4343
"https://azuredatabricks.net/",
4444
"ce34e7e5-485f-4d76-964f-b3d2b16d1e4f",
4545
"https://azure-devices-provisioning.net"
46-
]
46+
] # TODO: Cloud Shell IMDS will remove that list soon. What shall we do then?
4747
for a in cloud_shell_supported_audiences:
4848
if scope.startswith(a): # This is an experimental approach
4949
return a
5050
return scope # Some scope would work as-is, such as the SSH Cert scope
5151

5252

5353
def _acquire_token(http_client, scopes, **kwargs):
54-
kwargs.pop("correlation_id", None) # IMDS does not use correlation_id
5554
resp = http_client.post(
5655
"http://localhost:50342/oauth2/token",
5756
data=dict(
@@ -72,6 +71,11 @@ def _acquire_token(http_client, scopes, **kwargs):
7271
"expires_in": int(payload["expires_in"]),
7372
"token_type": payload.get("token_type", "Bearer"),
7473
}
74+
## Note: Decided to not surface resource back as scope,
75+
## because they would cause the downstream OAuth2 code path to
76+
## cache the token with a different scope and won't hit them later.
77+
#if payload.get("resource"):
78+
# oauth2_response["scope"] = payload["resource"]
7579
if payload.get("refresh_token"):
7680
oauth2_response["refresh_token"] = payload["refresh_token"]
7781
return oauth2_response

0 commit comments

Comments
 (0)