【发布时间】:2019-12-16 13:40:47
【问题描述】:
所以,我已经为此工作了几天,但我错过了一些东西。我正在尝试创建一个Xamarin 表单应用程序,该应用程序使用OAuth2 身份验证连接到云会计包。我一直在研究here 中的示例。但我就是无法让重定向工作。很可能是一些简单的事情,但我没有看到或理解
我根据示例创建了身份验证器,将重定向 url 设置为 https://com.myproject.myapp/oauth2redirect。
var authenticator = new OAuth2Authenticator(
<ClientId>,
null,
"openid profile email accounting.transactions accounting.settings offline_access",
new <AuthoriseationEndpoint>,
new Uri("https://com.myproject.myapp/oauth2redirect"),
new <TokenEndpoint>,
null,
true);
然后,我在我的 Android 项目中使用 intentFilter 创建了一个新的 activity
[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionView },
Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
DataSchemes = new[] { "com.myproject.myapp" },
DataPath = "/oauth2redirect")]
public class CustomUrlSchemeInterceptorActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var uri = new Uri(Intent.Data.ToString());
// Load redirectUrl page
AuthenticationState.Authenticator.OnPageLoading(uri);
Finish();
// Create your application here
}
}
当我运行我的应用程序时,登录屏幕会按预期弹出。我的应用程序在云应用程序中注册正常,但重定向不起作用。我只是收到一个浏览器错误,说无法访问该站点。 Server找不到IP地址DNS_PROBE_FINISHED_NXDOMAIN
【问题讨论】:
标签: c# android xamarin.forms oauth-2.0