Auth0 Home Blog Docs

Xamarin - Lock freezes after logging in, after updating VS2017

xamarin
lock-xamarin
vsts
vs2017-aspnet-core-2

#1

Days of trial and error lead me to suspect it’s the Xamarin version that the VS2017 update also updated which has broken it. The problem is Microsoft ties Xamarin versions in with VS version now, so downgrading Xamarin to a version that works loses support for Android SDK 26 which is now a mandatory minimum on the Play Store.

Mainly been debugging on Android but also happens with iOS. Tried multiple Android SDK versions but doesn’t seem any correlation here.

Building same code with VS prior to VS2017 (which we have on our VSTS CI server server - VSTS’s Hosted agent) sees things working fine as they have been for a long time. Using VSTS’s “Hosted VS2017” agent suddenly breaks lock again like local installation of VS2017.

Have tried OIDC flow using Auth0.OIDCClient and previous non-OIDC lock using the old Xamarin.Auth0Client - both exhibit the same freezing behavior with LoginAsync.

Can’t see any error information as to why Lock freezes with ‘hourglass’ stopping. Auth0 dashboard shows successful login.

Thinking I might have to abandon the lock unless someone knows what might cause this.


#2

If you see a successful login in Auth0, this could be happening because the browser instance is not picking up the callback URL.
These native OIDC clients work by opening the browser, redirecting the user to the /authorize endpoint and then waiting for the redirect flow to end up in the callback URL, which is where the authentication server sends the response back to the application. The application gets notified that the callback URL in different ways, depending on the platform and the version.
I would first check that the callback URLs are registered properly and that the places in the app where you configure the bundle identifier/package name are all correctly set.

Have you tried our Xamarin samples from the quickstarts in VS 2017?


#3

Thanks for the suggestions - the callback URL was ok but tweaking config until the sample app worked I saw Auth0 returns to the app via an intent. Previously I was just awaiting the end of the loginsync and continuing on. There must be some changed behavior here between the two VS/Xamarins versions as it’s very reproducible going between VS2015 which works and VS2017 which doesn’t.

Regardless, adding the intent capture fixes things for me - at least on Android. Yet to explored iOS.

Thanks


#4

Cool! If you can share how your changes look on code, it might help other users as well.


#5

Sure - so the issue was since upgrading to VS2017, the user = await authclient.LoginAsync(); call would never continue after entering login details. The lock screen would show the spinner spinning for a few seconds then freeze until a good 20 seconds later a timeout would occur. In VS2015 however, code would continue straight after the await after logging in.

For VS2017, I had to follow what the sample app was doing - i.e. first register the intent to listen for:

[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "{your package name}",
DataHost = "{your Auth0 domain|",
DataPathPrefix = "/android/{your package name}/callback")]
public  class MainActivity { ....

and then handling the intent by returning to line in the code after the await:

protected override void OnNewIntent(Intent intent)
{
    ActivityMediator.Instance.Send(intent.DataString);
}

Also ensure you have LaunchMode = LaunchMode.SingleTask defined in your Activity attribute to stop a new instance of your app running.