Esri / arcgis-maps-sdk-dotnet-samples

Sample code for ArcGIS Maps SDK for .NET – WPF, WinUI, .NET MAUI
Apache License 2.0
414 stars 518 forks source link

401 Unauthorized Error on Xamarin Forms #651

Closed Rhozero closed 3 years ago

Rhozero commented 5 years ago

I am trying to add IWA authentication to a Xamarin Forms app to access our hosted ArcGIS portal. Everything works as expected on UWP, however Xamarin Forms Android and iOS throw a 401 Unauthorized error when trying to authenticate.

I tested with your sample code against our hosted portal and saw the same behaviour.

I created a ticket with ESRI support and they responded to me after reproducing the error to post a bug here.

Reproduces: • Xamarin Forms Android • Xamarin Forms iOS • Xamarin Android Does Not Reproduce: • Xamarin Forms UWP • .NET UWP

Esri Case #02319161

nCastle1 commented 5 years ago

Hi @Rhozero,

As a first step toward diagnosing the issue, can you please confirm that you've got your Android and Forms Android apps configured to use the 'Managed' http client handler?

You can see Microsoft's doc for the exact steps.

Rhozero commented 5 years ago

Hi @nCastle1

It is configured to use the default. I will try the code again with the HttpClient set to managed. I am in need of using TLS 1.2 however. Do I also need to use the managed SSL/TLS implementation? Will this support TLS 1.2?

Rhozero commented 5 years ago

Hi @nCastle1,

I tried the sample Xamarin Forms app in Android using the managed HttpClient implementation and both the Managed and Default SSL/TLS and it authenticates against the portal with both, however the returned maps only load using the default SSL/TLS implementation.

I did notice however, the returned web maps do not return any web maps I have created in my portal, just the maps available in the ESRI Living Atlas.

I tried to implement the same code in my Xamarin Forms application using the managed HTTPClient in Android, and I am still getting a 401 unauthorized error

mbranscomb commented 3 years ago

@Rhozero Thanks for reporting this issue. We have an associated issue in our internal Git repo to track updating the enterprise authentication sample(s).

mbranscomb commented 3 years ago

IWA support was initially impacted in Xamarin.Android SDK version 10.0.0.43 which is installed with Visual Studio 2019 version 16.3.0 (Sept 2019). In that release, the internal implementation of the managed System.Net.Http.HttpClientHandler was updated to follow the .NET Core (CoreFX) implementation SocketsHttpHandler (https://github.com/mono/mono/pull/13338) which does not currently support IWA via NTLM or Kerberos in Android.

Relevant links: https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-v16.3#xamarin https://docs.microsoft.com/en-us/xamarin/android/release-notes/10/10.0#mono-framework-version-update-to-64 https://developercommunity.visualstudio.com/t/last-visual-studio-update-brakes-ntlm-authenticati/756697

Microsoft provided a workaround in Xamarin.Android SDK version 10.2.0.100 installed with Visual Studio 2019 version 16.5 (March 2020). That workaround enabled developers to revert the Http Handler to the previous "Managed" MonoWebRequestHandler handler which is now referred to as "Legacy" (note this is marked obsolete by Microsoft and is no longer actively maintained). Note this workaround is not valid for developers using ArcGIS where TLS 1.2 is required. The former "Managed" client handler on Android does not support TLS 1.2+.