简体   繁体   English

.NET MAUI WebAuthenticatorResult 不适用于 Strava

[英].NET MAUI WebAuthenticatorResult not working for Strava

I am creating a .NET MAUI app that is going to get some data from the Strava API.我正在创建一个 .NET MAUI 应用程序,它将从 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:当我尝试使用 WebAuthenticatorResult 类来获取访问令牌时,传递 URI 和 callbackURI 我收到以下错误:

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".在 Strava 上,我的授权回调域设置为字面意义上的“myapp.com”。

When I try to URL directly on the browser it works (sorry, it is in portugues):当我尝试直接在浏览器上输入 URL 时,它可以工作(对不起,它是葡萄牙语):

success when trying directly on the browser直接在浏览器上尝试时成功

Anybody has any idea?有人有什么想法吗?

If you check part Get started of document Xamarin.Essentials: Web Authenticatorenter ,you will find that:如果您检查文档Xamarin.Essentials: Web Authenticatorenter的部分入门,您会发现:

Android requires an Intent Filter setup to handle your callback URI. Android 需要一个 Intent Filter 设置来处理你的回调 URI。 This is easily accomplished by subclassing the WebAuthenticatorCallbackActivity class:这很容易通过WebAuthenticatorCallbackActivity类来实现:

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.如果您的项目的目标 Android 版本设置为Android 11 (R API 30) ,您必须使用符合新包可见性要求的查询来更新您的 Android 清单。

Open the AndroidManifest.xml file under the Properties folder and add the following inside of the manifest node:打开 Properties 文件夹下的AndroidManifest.xml文件,并在清单节点中添加以下内容:

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

For more details, you can check: Xamarin.Essentials: Web Authenticator .有关更多详细信息,您可以查看: Xamarin.Essentials: Web Authenticator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM