.Net Maui Android app with Google login using WebAuthenticator doesn't work

1.4k Views Asked by At

The Apple login works great in my iOS app. I've configured the server for Google, but can't get it to work. It's an Asp.net 6.0 Blazor WebAssembly API.

This line of code gets called in my Android app, but nothing is returned.

result = await WebAuthenticator.Default.AuthenticateAsync(authUrl, callbackUrl);

I configured the AuthController using this example.

https://github.com/dotnet/maui/blob/main/src/Essentials/samples/Sample.Server.WebAuthenticator/Controllers/MobileAuthController.cs

This line of code executes in my AuthController.

// Not authenticated, challenge
await Request.HttpContext.ChallengeAsync(scheme);

The Android app is targeting net6.0-Android31. The minimum target is net6.0-Android30. My test device is an Android emulator running API 31. I'm running Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.3.6 with Xamarin.Android.SDK version 13.0.0.0.

I also added this line in my MauiProgram.cs file.

builder.Services.AddSingleton(WebAuthenticator.Default);

Does anyone know how to get this to work? Thanks!

1

There are 1 best solutions below

7
On

This line of code gets called in my Android app, but nothing is returned.

At first can you try to debug or get the response code of this request? In addition, how do you do the authentication? With a web browser or the webview in the android. It seems the webauthenticator can't be used with Google.

You can check this case which tried to use WebAuthenticator with Google. Furthermore, according to this issue on the github, you need to change the redirect url in the WebAuthenticator.Default.AuthenticateAsync(authUrl, callbackUrl);.