IdentityModel / IdentityModel.OidcClient

Certified C#/NetStandard OpenID Connect Client Library for native mobile/desktop Applications (RFC 8252)
Apache License 2.0
593 stars 172 forks source link

Error loading discovery document on iOS. #347

Closed ErlingMK closed 2 years ago

ErlingMK commented 2 years ago

Hello

I get an issue when calling both OidcClient(options).PrepareLoginAsync() and OidcClient(options).LoginAsync().

System.InvalidOperationException: Error loading discovery document: Error connecting to <redacted url>. The type initializer for 'System.Text.Json.JsonSerializer' threw an exception.. ---> System.TypeInitializationException: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception. ---> System.ExecutionEngineException: Attempting to JIT compile method 'int System.Text.Json.JsonWriterHelper:NeedsEscaping (System.ReadOnlySpan`1<byte>,System.Text.Encodings.Web.JavaScriptEncoder)' while running in aot-only mode. See https://docs.microsoft.com/xamarin/ios/internals/limitations for more information.

  at System.Text.Json.JsonEncodedText.EncodeHelper (System.ReadOnlySpan`1[T] utf8Value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00000] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.TranscodeAndEncode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00033] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.Encode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.Encode (System.String value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonSerializer..cctor () [0x00042] in <cb68364b029e41c3bf425990b94c94d9>:0 
   --- End of inner exception stack trace ---
  at IdentityModel.Jwk.JsonWebKeySet..ctor (System.String json) [0x00024] in D:\a\IdentityModel\IdentityModel\src\Jwk\JsonWebKeySet.cs:55 
  at IdentityModel.Client.JsonWebKeySetResponse.InitializeAsync (System.Object initializationData) [0x0001b] in D:\a\IdentityModel\IdentityModel\src\Client\Messages\JsonWebKeySetResponse.cs:28 
  at IdentityModel.Client.ProtocolResponse.FromHttpResponseAsync[T] (System.Net.Http.HttpResponseMessage httpResponse, System.Object initializationData) [0x0024a] in <9a8c73072b5e431fba19cf713e652333>:0 
  at IdentityModel.Client.HttpClientJsonWebKeySetExtensions.GetJsonWebKeySetAsync (System.Net.Http.HttpMessageInvoker client, IdentityModel.Client.JsonWebKeySetRequest request, System.Threading.CancellationToken cancellationToken) [0x00285] in D:\a\IdentityModel\IdentityModel\src\Client\Extensions\HttpClientJsonWebKeySetExtensions.cs:70 
  at IdentityModel.Client.HttpClientDiscoveryExtensions.GetDiscoveryDocumentAsync (System.Net.Http.HttpMessageInvoker client, IdentityModel.Client.DiscoveryDocumentRequest request, System.Threading.CancellationToken cancellationToken) [0x00404] in D:\a\IdentityModel\IdentityModel\src\Client\Extensions\HttpClientDiscoveryExtensions.cs:108 
   --- End of inner exception stack trace ---
  at IdentityModel.OidcClient.OidcClient.EnsureProviderInformationAsync (System.Threading.CancellationToken cancellationToken) [0x00155] in /_/src/OidcClient/OidcClient.cs:407 
  at IdentityModel.OidcClient.OidcClient.EnsureConfigurationAsync (System.Threading.CancellationToken cancellationToken) [0x00023] in /_/src/OidcClient/OidcClient.cs:371 
  at IdentityModel.OidcClient.OidcClient.LoginAsync (IdentityModel.OidcClient.LoginRequest request, System.Threading.CancellationToken cancellationToken) [0x00070] in /_/src/OidcClient/OidcClient.cs:73 
  at DIPS.Mobile.Essentials.InternalServices.IdentityFacade.CreateAuthorizeRequest () [0x000a6] in /Users/emk/code/DIPS.Mobile.Essentials/DIPS.Mobile.Essentials/DIPS.Mobile.Essentials/InternalServices/IdentityFacade.cs:44 

The url is valid. Works when pasted in to a browser.

IdentityModel.OidcClient version 5.0.0 Xamarin.Forms version 5.0.0.2291 Xamarin.iOS version 15.4.0.0

leastprivilege commented 2 years ago

Seems to be related to the JSON library. Did you do some research already?

ErlingMK commented 2 years ago

I did, but just discovered a workaround. Not sure how I missed that.

https://github.com/mono/mono/issues/20805#issuecomment-791440473. Comment on similar issue. Adding the two packages and targeting .NetStandard 2.1 resolves it.

Also, downgrading to IdentityModel.OidcClient version 4.0.0 resolves it without doing anything of the above.

I will close this since the issue isn‘t related to this package

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.