Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Custom HttpClient exceptions not propagated #1575

Closed
leonluc-dev opened this issue Apr 5, 2019 · 4 comments
Closed

Custom HttpClient exceptions not propagated #1575

leonluc-dev opened this issue Apr 5, 2019 · 4 comments
Assignees
Labels
Milestone

Comments

@leonluc-dev
Copy link

leonluc-dev commented Apr 5, 2019

Which Version of ADAL are you using ?
5.0.2-preview

Which platform has the issue?
Xamarin.Android

What authentication flow has the issue?

  • Desktop / Mobile
    • [*] Interactive
    • [*] Token renewal

Is this a new or existing app?
The app is in production, and I have upgraded to a new version of ADAL

Repro

AuthenticationContext ctx = new AuthenticationContext(endpoint, false, TokenCache.DefaultShared, new HttpClientFactory());
return (await ctx.AcquireTokenSilentAsync(resource, clientId)).AccessToken;

 public class HttpClientFactory : IHttpClientFactory
 {
       public HttpClient GetHttpClient()
       {
            return new HttpClient(); //Automatically initialized with a AndroidClientHandler instead of a HttpMessageHandler due to Xamarin.Android project settings
       }
}

Expected behavior
Any HttpClient exception getting propagated to the caller (as an InnerException to an AdalServiceException), as is default behaviour without a IHttpClientFactory instance passed to the context.

Actual behavior
Any exception seems to be ignored and the response is parsed.
Which fails due to there being no response, making the library throw up a parsing exception.

Additional context/ Logs / Screenshots
The exception that occurs when the parsing of the non-existing response fails:


System.Runtime.Serialization.SerializationException: Expecting element 'root' from namespace ''.. Encountered 'None'  with name '', namespace ''.
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject (System.Runtime.Serialization.XmlReaderDelegator xmlReader, System.Boolean verifyObjectName) [0x00069] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject (System.Runtime.Serialization.XmlReaderDelegator reader, System.Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) [0x00000] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, System.Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) [0x00072] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, System.Boolean verifyObjectName) [0x00000] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) [0x0000d] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.IO.Stream stream) [0x00017] in <eddf66ae34d240a1bb39744e055a9c28>:0 
  at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Helpers.EncodingHelper.DeserializeResponse[T] (System.String response) [0x00024] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Internal\Helpers\EncodingHelper.cs:247 
  at Microsoft.Identity.Core.OAuth2.OAuthClient+<GetResponseAsync>d__18`1[T].MoveNext () [0x000fb] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Core\OAuth2\OAuthClient.cs:63 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.Identity.Core.OAuth2.OAuthClient+<GetResponseAsync>d__17`1[T].MoveNext () [0x00028] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Core\OAuth2\OAuthClient.cs:45 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase+<SendHttpMessageAsync>d__75.MoveNext () [0x00053] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Internal\Flows\AcquireTokenHandlerBase.cs:404 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase+<SendTokenRequestByRefreshTokenAsync>d__73.MoveNext () [0x0007f] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Internal\Flows\AcquireTokenHandlerBase.cs:345 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase+<RefreshAccessTokenAsync>d__74.MoveNext () [0x00059] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Internal\Flows\AcquireTokenHandlerBase.cs:366 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase+<RunAsync>d__60.MoveNext () [0x006f8] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\Internal\Flows\AcquireTokenHandlerBase.cs:240 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+<AcquireTokenSilentCommonAsync>d__43.MoveNext () [0x00084] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\AuthenticationContext.cs:625 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+<AcquireTokenSilentAsync>d__30.MoveNext () [0x0003f] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\AuthenticationContext.cs:378 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+<AcquireTokenSilentAsync>d__29.MoveNext () [0x00038] in D:\a\1\s\src\Microsoft.IdentityModel.Clients.ActiveDirectory\AuthenticationContext.cs:365 
--- End of stack trace from previous location where exception was thrown ---
@jmprieur
Copy link
Contributor

@jennyf19

@jennyf19
Copy link
Contributor

@gameleon-dev Can you try this branch and see if it still repros for you? thanks.

@bgavrilMS
Copy link
Member

Yes, I see the regression. I believe @jennyf19 's fix will address it and I just approved the PR. We will try to get a release out as soon as possible.

@jennyf19 jennyf19 added the Fixed label Apr 18, 2019
@jennyf19 jennyf19 added this to the 5.0.3 milestone Apr 18, 2019
@jennyf19
Copy link
Contributor

Included in 5.0.3-preview release

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants