dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

WebAuthenticator in Android not working #6534

Closed PhilippRoessner closed 2 years ago

PhilippRoessner commented 2 years ago

Description

When subclassing the WebAuthenticatorCallbackActivity, I get a lot of errors like "The type or namespace name '....' could not be found(are you missing a using directive or an assembly reference?)

image

Steps to Reproduce

  1. Create a new MAUI App
  2. Follow instructions for WebAuthenticator for Android https://docs.microsoft.com/en-us/xamarin/essentials/web-authenticator?tabs=ios#using-webauthenticator
  3. run

Version with bug

Release Candidate 1 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

12

Did you find any workaround?

no

Relevant log output

No response

Redth commented 2 years ago

You're missing the namespace import (you could fully qualify it like below) public class WebAuthenticatorCallbackActivity : global::Microsoft.Maui.Authentication.WebAuthenticatorCallbackActivity

PhilippRoessner commented 2 years ago

@Redth thanks, I tried that but it's still not working with the same errors. What would be the namespace for the class attributes?

shurkin commented 2 years ago

I have the same issue

shurkin commented 2 years ago

Hi @PhilippRoessner,

I found the solution. You have to add

Exported = true in Activity attribute.


[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = "yourscheme")]
public class WebAuthenticationCallbackActivity : WebAuthenticatorCallbackActivity
{
}```
PhilippRoessner commented 2 years ago

@shurkin YES! Thanks, it's working now :-)

Joren-Thijs-KasparSolutions commented 2 years ago

I still get this error using RC2. I just switched to copying the strings as literals image

Joren-Thijs-KasparSolutions commented 2 years ago

That being said it's still not working for me. i still get an error when trying to login:

System.InvalidOperationException: You must subclass the `WebAuthenticatorCallbackActivity` and create an IntentFilter for it which matches your `callbackUrl`.
   at Microsoft.Maui.Authentication.WebAuthenticatorImplementation.AuthenticateAsync(WebAuthenticatorOptions webAuthenticatorOptions) in D:\a\_work\1\s\src\Essentials\src\WebAuthenticator\WebAuthenticator.android.cs:line 63
   at App.Features.Login.WebAuthenticatorBrowser.InvokeAsync(BrowserOptions options, CancellationToken cancellationToken)

I don't understand do I need to link the activity somewhere on startup? why can I not find any docs on this?