Essentials: [Bug] WebAuthenticator - Android - Null Reference Exception WebAuthenticatorIntermediateActivity.android.cs

Created on 11 Dec 2020  路  4Comments  路  Source: xamarin/Essentials

Description

On Android SDK 30, with 1.6 pre 5 of Xamarin Essentials, on launch of the browser tabs page for login, on line 24 of WebAuthenticatorIntermediateActivity.android.cs I get a null reference exception. extras is null. savedInstanceState is null, and Intent.Extras is also null.

I have the activity setup per the docs (direct copy with my own callback_scheme) The error is a very unhelpful "Null Reference Exception" message with 0 stack or anything. I had to add the actual Xamarin Essentials project from github to get it to fail on this.

Steps to Reproduce

  1. Create a Xamarin Forms project
  2. Update Android to Target SDK 30 (not sure if this is required)
  3. Call the standard WebAuthenticator.AuthenticateAsync (I'm on local network calling into my dev machine that has the port opened and works fine for UWP)
  4. The browser launches and THEN before you can type in your login the app crashes.

Expected Behavior

Should go through like UWP does.

Actual Behavior

Crash on browser launch for login and password.

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:

    • Android: 30

  • Affected Devices: Pixel C emulator created by AVD Manager.
bug

Most helpful comment

Same problem here - tested on a physical Pixel 5.
I think it has something to do with targeting Android 30 and the privacy changes that came with it:

Adding this snippet to the AndroidManifest fixed the problem for me:

<queries>
    <intent>
        <action android:name="android.support.customtabs.action.CustomTabsService" />
    </intent>
</queries>

All 4 comments

Can you test on an actual device? Does the sample in this repo work for you?

I can't seem to repro this with our sample. In fact, this should not happen. Intent should not be null as that was the intent used to launch the activity. Bot, not only that, the Extras should not be null because we _always_ add an extra to that intent to launch. That is how the browser is being launched... In fact, in order for the browser to be launched, it had to have loaded the extras and read the browser intent from there...

I tried on a device and the emulator and was not able to repro.

I'm trying to find a real device but my emulator is a Pixel C emulator using SDK 30 created in the AVD Manager.

This is all I get: System.NullReferenceException
Message=Object reference not set to an instance of an object.

Are you set to Android 30 as your target sdk?

I created a brand new emulator and in that case, because of no caching the error occurs when it comes back from the google chrome tabs.

What else can I get you to help find this?

Same problem here - tested on a physical Pixel 5.
I think it has something to do with targeting Android 30 and the privacy changes that came with it:

Adding this snippet to the AndroidManifest fixed the problem for me:

<queries>
    <intent>
        <action android:name="android.support.customtabs.action.CustomTabsService" />
    </intent>
</queries>

The team working on the MSAL lib is tracking a similar, related problem: https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2139

Was this page helpful?
0 / 5 - 0 ratings