Select to view content in your preferred language

ArcGISHttpClientHandler is obsolete: way to disable PreAuthenticate with ArcGISHttpMessageHandler?

1302
7
09-11-2023 03:58 PM
FelicityRhone
Occasional Contributor

Hi,

I'm upgrading an app from Xamarin Forms/ArcGIS Runtime 100.15 to Maui/Maps SDK 200.0.

We're using ArcGISHttpClientHandler, and see that it is now marked as obsolete and we're supposed to use ArcGISHttpMessageHandler instead. Unfortunately, it seems like we need to be able to set ArcGISHttpClientHandler.PreAuthenticate to false in order to support IWA on Android. If we do not set this value then the app hangs when trying to make a request to services in a portal secured with IWA.
When I tried to switch over to using ArcGISHttpMessageHandler, this property isn't available on the handler, and I get the same hanging behaviour.
I have set credential.PreAuthenticateBehavior = PreAuthenticateBehavior.Disabled on the ArcGISNetworkCredential that we create for IWA but that doesn't help.

There are also a couple other properties we use on ArcGISHttpClientHandler: Credentials, UseDefaultCredentials and ServerCertificateCustomValidationCallback, which are also absent from the new ArcGISHttpMessageHandler - but PreAuthenticate is the only one I've confirmed (through testing) that we can't do without at the moment.

So, what to do? In the meantime we'll continue to use the obsolete ArcGISHttpClientHandler, but presumably we'll have to update it at some point. Is there some other equivalent to PreAuthenticate that we can use with the ArcGISHttpMessageHandler? Or can anyone point to a sample of using IWA on Android that might help? There was a known bug on Android for Esri's IWA samples for Xamarin Forms so I believe they removed that sample, but I still don't see an IWA sample in the Maui samples project although it should apparently work in Maui.

0 Kudos
7 Replies
PreetiMaske
Esri Regular Contributor

Can you please confirm the .NET version you are using?. FYI, With .NET 7 IWA is now supported on Android. If you are not using .NET 7, I suggest updating to .NET 7 and re-test your IWA workflow.

0 Kudos
FelicityRhone
Occasional Contributor

We are using .NET 7.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Thanks for confirming. In that case we might need some more information to replicate the issue you're referring to. We are not currently aware of IWA issues on Android.

Having said that, any chance you could give v200.2.0 a go and see if it still reproduces? There's been quite a lot of fixes over the past year, and as mentioned, IWA on Android wasn't really supported in MAUI until .NET 7 shipped - 200.2 is built for .NET 7 on Android.

0 Kudos
FelicityRhone
Occasional Contributor

Sure, I will try 200.2 when I have a chance and let you know how it goes.

FelicityRhone
Occasional Contributor

I tried upgrading our app to use 200.2.0 (it was 200.0.0 before) and it made no difference. To clarify our flow: when our credential handler gets a request from the IWA portal for an AuthenticationType.NetworkCredential, we ask the user for a username/password in our own basic authentication page. We create an ArcGISNetworkCredential from that info, and then try to make a request to the service uri to confirm that the creds are valid, which is the point where it hangs*.
Our challenge handler flow is unfortunately kinda complicated due to the workarounds we needed to add along the way to get everything working in the Xamarin Forms implementation. 

I then tried using our IWA portal in the ArcGIS Maps SDK .Net Samples project (.NET 7 and the 200.2 SDK), to get away from the extra stuff in our own project. 
I modified the ServerURL and WebMapID in OAuth.xaml.cs to point to our testing portal, and added AuthenticationManager.Current.RegisterServer with the IWA server's info. 
This did result in an IWA prompt coming up (cool!), but after entering my credentials I would get a 400 'invalid redirect_uri' error page instead of moving on to the ArcGIS portal sign in prompt (I did not change the "maui-ags-app://auth" redirect url that's in the sample). Does that sound expected? I'm not sure what I have to do differently with the redirect url to get that working, or if I'm missing something else, like if the challenge handler needs to do something different for the NetworkCredential vs Token AuthenticationType... If I can get it working in the sample maybe I can simplify things in our app to match.

* when we don't have the workarounds in place: disabling preauthentication as mentioned in my original post, and also setting the HttpClientHandlerImplementation for the project to the legacy mono implementation >_<

0 Kudos
dotMorten_esri
Esri Notable Contributor

Make sure you configure your oauth app settings in the portal to have a redirect url that matches what you have in the application. If there's a mismatch, you get the error you report.

If possible, any chance you could share something that reproduces the hang? Also where do you see the hang?

0 Kudos
dotMorten_esri
Esri Notable Contributor

Also want to add that there's currently a bug in the .NET 8 Preview, preventing IWA from working on Android. But as Preeti said, .NET 7 should "just work". It's actually a feature that was added to Android in .NET 7. It's also worth noting that .NET 6 is no longer supported by .NET MAUI.

Side note: ArcGISHttpMessageHandler is merely a delegate now. On Android it uses .NET's SocketsHttpHandler under the hood and should improve authentication across the board for Android, whereas with Xamarin.Android each message handler had their pros and cons.

0 Kudos