Xamarin Plaid OAuth -Xamarin的WebAuthenticator是否支持使用https://的重定向?

vsaztqbk  于 2023-04-18  发布在  其他
关注(0)|答案(1)|浏览(105)

我试图在我的Xamarin应用程序中实现API的银行Plaid OAuth部分,遇到了很多麻烦。对于初学者来说,Plaid需要一个https://yoururlhere.com的OAuth回调URL,如果WebAuthenticator支持它,我就无法弄清楚。我只看到了packagename的示例。
Plaid确实允许Android软件包名称,但不允许iOS...我应该这样做吗?iOS会发生什么?我需要在Android和iOS上实现这一点。据我所知,我不会离开我的Xamarin应用程序,因为这一切都是通过webview完成的,因此遵循这种方法是没有意义的正确的?
为了更好地理解我正在尝试做的事情,我简化了下面的代码和名称。

MainViewModel.cs

// successfully has linkToken before this point

var authResult = await WebAuthenticator.AuthenticateAsync(
    new Uri("https://cdn.plaid.com/link/v2/stable/link.html?isWebview=true&token=" + linkToken),
    new Uri("https://someurl.net/link/v2/oauth/redirect")
);

Web身份验证回调活动.cs.

[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 = "https")]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
     public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
     {
          base.OnCreate(savedInstanceState, persistentState);
     }
}

我的datascheme应该是什么?只是https://?还是我的完整URL?

AndroidManifest.xaml

我在这里添加了正确的必需品
我还没有机会看到iOS的必需品,但我们现在可以忽略这些。
我还需要拦截这个回调,并从重定向的URL发出新的http请求来完成令牌,我也不知道该怎么做
任何帮助实施任何部分,这将是非常感谢

aemubtdh

aemubtdh1#

Microsoft文档提供了有关Xamarin.Essentials: Web Authenticator的示例
对于Android,Android需要设置Intent Filter来处理回调URI。这可以通过子类化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
{
}

相关问题