【发布时间】:2018-10-09 03:58:41
【问题描述】:
我想通过 auth0 登录我的 xamarin.android 应用程序。我发现这个描述它的教程非常好。
我只是在 c# 上使用 xamarin.android 而不是“纯”android 应用程序。
如您所见,我收到了来自 auth0 的有效回复,callback?code={code}
但似乎意图激活方法存在一些问题。 (它无法以正确的方案解析响应。也许,它假定它是 url 地址并通过浏览器进行重定向调用)。
有我的MainActivity代码:
usings ***
namespace myApp.intake.Mobile.Droid
{
[Activity(Label = "App",
Icon = "@drawable/icon",
Theme = "@style/MainTheme",
MainLauncher = true,
LaunchMode = LaunchMode.SingleInstance,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(
new[] { Intent.ActionView },
DataScheme = "myApp.intake.mobile",
DataHost = "myApp-dev.auth0.com",
DataPathPrefix = "/android/myApp.intake.mobile/callback")]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
client = new Auth0Client(new Auth0ClientOptions
{
Domain = "myApp-dev.auth0.com",
ClientId = "************", //real clientId
Activity = this
});
Forms.Init(this, bundle);
LoadApplication(new App());
this.PerformAuth0Login();
}
protected override async void OnNewIntent(Intent intent)
{
// I have to get redirected here but it just throw the mentioned error!!!!!!
base.OnNewIntent(intent);
var loginResult = await client.ProcessResponseAsync(intent.DataString, authorizeState);
var sb = new StringBuilder();
if (loginResult.IsError)
{
// logic to handle the error
}
// next business logic
}
#region Private Logic
private async void PerformAuth0Login()
{
// Prepare for the login
authorizeState = await client.PrepareLoginAsync();
// Send the user off to the authorization endpoint
var uri = Android.Net.Uri.Parse(authorizeState.StartUrl);
var intent = new Intent(Intent.ActionView, uri);
intent.AddFlags(ActivityFlags.NoHistory);
StartActivity(intent); //I think problem here..
}
#endregion
#region Private Fields
private Auth0Client client;
private AuthorizeState authorizeState;
#endregion
}
}
提前感谢您的帮助!
【问题讨论】:
-
您到底想从我们这里得到什么
-
@G.hakim 只是帮助解决这个错误问题(net:ERR_UNKNOWN_URL_SCHEME)。使用代码将应用程序重定向到 OnNewIntent 方法以完成身份验证。
标签: android xamarin xamarin.android auth0