Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebAuthenticator] NullReferenceException on CallbackResult #3760

Closed
Hantse opened this issue Dec 14, 2021 · 6 comments
Closed

[WebAuthenticator] NullReferenceException on CallbackResult #3760

Hantse opened this issue Dec 14, 2021 · 6 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 platform/iOS 🍎 platform/windows 🪟 t/bug Something isn't working
Projects
Milestone

Comments

@Hantse
Copy link

Hantse commented Dec 14, 2021

Description

I create new MAUI Application and i try to use WebAuthenticator.
I initialise everything i see in sample app in repository.
I launch app, click on button and arrive to page for authenticate on web.
Authentication work, and callback is launch to app.
App try to launch, i pass in WebAuthenticationCallbackActivity constructor, but after the application crash, with "NullReferenceException", log are not enough clear to see where that's come.

Repository :
https://github.com/Hantse/maui-webauthenticator

Steps to Reproduce

  1. Clone repository https://github.com/Hantse/maui-webauthenticator
  2. Launch project as Normal or Blazor
  3. Click on button to start authenticate process

Version with bug

Preview 10 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows

Affected platform versions

Android

Did you find any workaround?

No response

Relevant log output

No response

@Hantse Hantse added the t/bug Something isn't working label Dec 14, 2021
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Dec 14, 2021
@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label Dec 16, 2021
@PureWeen PureWeen added the fatal label Jan 5, 2022
@enisn
Copy link

enisn commented Feb 20, 2022

Same problem occurs:

  • Here is my activity:
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
    Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
    DataScheme = CALLBACK_SCHEME)]
public class MyWebAuthenticatorCallbackActivity : Microsoft.Maui.Essentials.WebAuthenticatorCallbackActivity
{
    const string CALLBACK_SCHEME = "myapp";

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }
}
  • Callback URL is that: myapp://auth-callback

  • And the log

...
[monodroid-assembly] open_from_bundles: failed to load assembly System.Security.Cryptography.Algorithms.dll
[monodroid-assembly] open_from_bundles: failed to load assembly System.Security.Cryptography.Primitives.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Security.Cryptography.Algorithms.dll [External]
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Security.Cryptography.Primitives.dll [External]
Resolved pending breakpoint at 'OidcClientFactory.cs:43,1' to void MauiApp1.WebAuthenticatorBrowser.<InvokeAsync>d__0.MoveNext () [0x000f0].
[monodroid-assembly] open_from_bundles: failed to load assembly Xamarin.AndroidX.Browser.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/Xamarin.AndroidX.Browser.dll [External]
Resolved pending breakpoint at 'MainActivity.cs:27,1' to void MauiApp1.MyWebAuthenticatorCallbackActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00000].
**System.NullReferenceException:** 'Object reference not set to an instance of an object.'

Logs doesn't help. There is no stacktrace in logs.

Also I've tried to check to find what can be null, I saw savedInstanceState is null but it doesn't matter because there is a check for that here:

var extras = savedInstanceState ?? Intent.Extras;

@enisn
Copy link

enisn commented Feb 20, 2022

Hi @Hantse

I've found a solution while reviewing source code of WebAuthenticator

It uses CustomTabs:

var customTabsActivityManager = CustomTabsActivityManager.From(parentActivity);

So adding following part into your AndroidManifest.xml solved my problem:

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

It should be between <manifest> tags.

After adding it, NullReferenceException was solved 👍

@Hantse
Copy link
Author

Hantse commented Mar 17, 2022

Hello, I try your solution thx :)

@shimingsg shimingsg added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/verified Verified / Reproducible Issue ready for Engineering Triage labels Mar 18, 2022
@Redth Redth added this to the 6.0.300 milestone Mar 23, 2022
@jfversluis
Copy link
Member

Could someone please confirm this is still an issue in the current releases?

@enisn
Copy link

enisn commented Mar 30, 2022

Could someone please confirm this is still an issue in the current releases?

It's working on all platforms with preview.14 right now.

Only Windows has a problem and it has own issue: (#2702)

@jfversluis
Copy link
Member

Perfect, thanks @enisn! Then I'm going to assume most of this works now unless someone tells me otherwise :)

Triage automation moved this from New to Done Mar 30, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/android 🤖 platform/iOS 🍎 platform/windows 🪟 t/bug Something isn't working
Projects
No open projects
Development

No branches or pull requests

8 participants