@@ -604,6 +604,16 @@ def _build_telemetry_context(
604
604
self ._telemetry_buffer , self ._telemetry_lock , api_id ,
605
605
correlation_id = correlation_id , refresh_reason = refresh_reason )
606
606
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
+
607
617
def _get_regional_authority (self , central_authority ):
608
618
if not self ._region_configured : # User did not opt-in to ESTS-R
609
619
return None # Short circuit to completely bypass region detection
@@ -974,11 +984,7 @@ def authorize(): # A controller in a web app
974
984
** kwargs ))
975
985
if "access_token" in response :
976
986
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 )
982
988
telemetry_context .update_telemetry (response )
983
989
return response
984
990
@@ -1706,6 +1712,7 @@ def acquire_token_by_username_password(
1706
1712
** kwargs ))
1707
1713
if "access_token" in response :
1708
1714
response [self ._TOKEN_SOURCE ] = self ._TOKEN_SOURCE_IDP
1715
+ self ._adjust_response (response )
1709
1716
telemetry_context .update_telemetry (response )
1710
1717
return response
1711
1718
@@ -2008,6 +2015,8 @@ def acquire_token_interactive(
2008
2015
** kwargs ))
2009
2016
if "access_token" in response :
2010
2017
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
2011
2020
telemetry_context .update_telemetry (response )
2012
2021
return response
2013
2022
@@ -2117,6 +2126,7 @@ def initiate_device_flow(self, scopes=None, **kwargs):
2117
2126
headers = {msal .telemetry .CLIENT_REQUEST_ID : correlation_id },
2118
2127
** kwargs )
2119
2128
flow [self .DEVICE_FLOW_CORRELATION_ID ] = correlation_id
2129
+ self ._adjust_response (flow ) # AADSTS500207 would happen here, not at token endpoint
2120
2130
return flow
2121
2131
2122
2132
def acquire_token_by_device_flow (self , flow , claims_challenge = None , ** kwargs ):
@@ -2214,6 +2224,7 @@ def _acquire_token_for_client(
2214
2224
claims = _merge_claims_challenge_and_capabilities (
2215
2225
self ._client_capabilities , claims_challenge )),
2216
2226
** kwargs )
2227
+ self ._adjust_response (response )
2217
2228
telemetry_context .update_telemetry (response )
2218
2229
return response
2219
2230
0 commit comments