@@ -604,6 +604,16 @@ def _build_telemetry_context(
604604 self ._telemetry_buffer , self ._telemetry_lock , api_id ,
605605 correlation_id = correlation_id , refresh_reason = refresh_reason )
606606
607+ def _adjust_response (self , response ): # Adjust response inline
608+ # Currently, this is used to provide better error message for CIAM CUD
609+ error_description = response .get ("error_description" , "" )
610+ if ("AADSTS500207" in error_description # Observed in most auth grants
611+ or "AADSTS900144" in error_description # Observed in ROPC
612+ ) and self ._oidc_authority and not self ._oidc_authority .endswith ("/v2.0" ):
613+ response ["error_description" ] = (
614+ 'Did you forget to append "/v2.0" to your oidc_authority? '
615+ + response ["error_description" ])
616+
607617 def _get_regional_authority (self , central_authority ):
608618 if not self ._region_configured : # User did not opt-in to ESTS-R
609619 return None # Short circuit to completely bypass region detection
@@ -974,11 +984,7 @@ def authorize(): # A controller in a web app
974984 ** kwargs ))
975985 if "access_token" in response :
976986 response [self ._TOKEN_SOURCE ] = self ._TOKEN_SOURCE_IDP
977- if ("AADSTS500207" in response .get ("error_description" , "" ) and
978- self ._oidc_authority and not self ._oidc_authority .endswith ("/v2.0" )):
979- response ["error_description" ] = (
980- 'Did you forget to append "/v2.0" to your oidc_authority? '
981- + response ["error_description" ])
987+ self ._adjust_response (response )
982988 telemetry_context .update_telemetry (response )
983989 return response
984990
@@ -1706,6 +1712,7 @@ def acquire_token_by_username_password(
17061712 ** kwargs ))
17071713 if "access_token" in response :
17081714 response [self ._TOKEN_SOURCE ] = self ._TOKEN_SOURCE_IDP
1715+ self ._adjust_response (response )
17091716 telemetry_context .update_telemetry (response )
17101717 return response
17111718
@@ -2008,6 +2015,8 @@ def acquire_token_interactive(
20082015 ** kwargs ))
20092016 if "access_token" in response :
20102017 response [self ._TOKEN_SOURCE ] = self ._TOKEN_SOURCE_IDP
2018+ self ._adjust_response (response ) # Note: It won't improve
2019+ # the error rendered in browser, but still better than nothing
20112020 telemetry_context .update_telemetry (response )
20122021 return response
20132022
@@ -2117,6 +2126,7 @@ def initiate_device_flow(self, scopes=None, **kwargs):
21172126 headers = {msal .telemetry .CLIENT_REQUEST_ID : correlation_id },
21182127 ** kwargs )
21192128 flow [self .DEVICE_FLOW_CORRELATION_ID ] = correlation_id
2129+ self ._adjust_response (flow ) # AADSTS500207 would happen here, not at token endpoint
21202130 return flow
21212131
21222132 def acquire_token_by_device_flow (self , flow , claims_challenge = None , ** kwargs ):
@@ -2214,6 +2224,7 @@ def _acquire_token_for_client(
22142224 claims = _merge_claims_challenge_and_capabilities (
22152225 self ._client_capabilities , claims_challenge )),
22162226 ** kwargs )
2227+ self ._adjust_response (response )
22172228 telemetry_context .update_telemetry (response )
22182229 return response
22192230
0 commit comments