Home > Software design >  .NET MAUI WebAuthenticatorResult not working for Strava
.NET MAUI WebAuthenticatorResult not working for Strava

Time:07-20

I am creating a .NET MAUI app that is going to get some data from the Strava API. When I try to use the WebAuthenticatorResult class to get the access token, passing the URI and the callbackURI I get the following error:

Error I am getting

The code I am using is this:

Code I am trying to run

On Strava, my authorization callback domain is set to literally "myapp.com".

When I try to URL directly on the browser it works (sorry, it is in portugues):

success when trying directly on the browser

Anybody has any idea?

CodePudding user response:

If you check part Get started of document Xamarin.Essentials: Web Authenticatorenter ,you will find that:

Android requires an Intent Filter setup to handle your callback URI. This is easily accomplished by subclassing the WebAuthenticatorCallbackActivity class:

const string CALLBACK_SCHEME = "myapp";

[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
    Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
    DataScheme = CALLBACK_SCHEME)]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
}

And if your project's Target Android version is set to Android 11 (R API 30) you must update your Android Manifest with queries that are used with the new package visibility requirements.

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node:

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

For more details, you can check:Xamarin.Essentials: Web Authenticator.

  • Related