Skip to content

Commit 0ecc477

Browse files
committed
Graceful fallback when account does not exist in broker
1 parent 607ee99 commit 0ecc477

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

msal/application.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,16 +1234,17 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
12341234
claims=_merge_claims_challenge_and_capabilities(
12351235
self._client_capabilities, claims_challenge),
12361236
)
1237-
if "error" not in response:
1238-
self.token_cache.add(dict(
1239-
client_id=self.client_id,
1240-
scope=response["scope"].split() if "scope" in response else scopes,
1241-
token_endpoint=self.authority.token_endpoint,
1242-
response=response.copy(),
1243-
data=kwargs.get("data", {}),
1244-
_account_id=response["_account_id"],
1245-
))
1246-
return _clean_up(response)
1237+
if response: # It means broker was able to provide a decisive outcome
1238+
if "error" not in response:
1239+
self.token_cache.add(dict(
1240+
client_id=self.client_id,
1241+
scope=response["scope"].split() if "scope" in response else scopes,
1242+
token_endpoint=self.authority.token_endpoint,
1243+
response=response.copy(),
1244+
data=kwargs.get("data", {}),
1245+
_account_id=response["_account_id"],
1246+
))
1247+
return _clean_up(response) # Then we use the broker's result
12471248
except ImportError:
12481249
logger.warning("PyMsalRuntime is not available")
12491250
result = _clean_up(self._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(

msal/wam.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def _acquire_token_silently(authority, client_id, account_id, scopes, claims=Non
139139
error = account.get_error()
140140
if error:
141141
return _convert_error(error, client_id)
142+
if not account.get_account(): # It happens when the account was not created by broker
143+
return
142144
params = pymsalruntime.MSALRuntimeAuthParameters(client_id, authority)
143145
params.set_requested_scopes(scopes)
144146
if claims:

0 commit comments

Comments
 (0)