Android Azure在Xamarin表单项目中与AAD和Google进行身份验证,授权后不会重定向回应用程序
Azure Active Directory Google+Auth Xamarin表单,PCL NuGet 2.4.0.282 Microsoft.Azure.Mobile.Client 4.0.0和4.0.2 成功登录后,我的手机不会返回到我的应用程序。我有两个测试手机和一个模拟器,它们在登录后显示不同的信息 电话1和授权: Phone 1 Google Auth它变灰并继续加载 电话2 AAD和谷歌认证: Emulator AAD和Google Auth: 我已经完成了这里关于堆栈溢出的所有工作,这很有意义,并且似乎适用于当前版本的NuGets。 这个人似乎有一个类似的问题,我,但谷歌登录 我已经尝试将代码集成到我的项目中。然后我将我的Azure信息输入到Xamarin的示例中: 我得到了同样的结果。我试过AAD和Google+Auth。登录后,它只停留在浏览器中。所以我觉得客户端代码必须是正确的。但是我找不到我的Azure服务器代码有任何混乱。我已经在具有C和Node.Js后端的项目中尝试过这一点。对于我的一个项目,我允许的外部重定向URL是ToDoList53172://easyauth.callback,在我的AndroidManifest.xml中如下所示:Android Azure在Xamarin表单项目中与AAD和Google进行身份验证,授权后不会重定向回应用程序,android,azure,authentication,xamarin.forms,azure-mobile-services,Android,Azure,Authentication,Xamarin.forms,Azure Mobile Services,Azure Active Directory Google+Auth Xamarin表单,PCL NuGet 2.4.0.282 Microsoft.Azure.Mobile.Client 4.0.0和4.0.2 成功登录后,我的手机不会返回到我的应用程序。我有两个测试手机和一个模拟器,它们在登录后显示不同的信息 电话1和授权: Phone 1 Google Auth它变灰并继续加载 电话2 AAD和谷歌认证: Emulator AAD和Google Auth: 我已经完成了这里关于堆栈
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.xamarin.sample.TodoAzure">
<uses-sdk android:minSdkVersion="15" />
<application android:label="TodoAzure" android:icon="@drawable/icon">
<activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" android:launchMode="singleTop" android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="ToDoList53172" android:host="easyauth.callback" />
</intent-filter>
</activity>
</application>
</manifest>
旧的:
我觉得我不应该发布所有其他代码。这一切都在上面发布的Xamarin示例项目中。如果人们认为我应该,我会的。
新的:
我正在添加更多的代码来帮助人们。我不想超载,但最好把所有信息都放在一个地方。这是我的MainActivity.cs代码
using System;
using System.Threading.Tasks;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Microsoft.WindowsAzure.MobileServices;
using Android.Webkit;
namespace TodoAzure.Droid
{
[Activity(Label = "TodoAzure.Droid",
Icon = "@drawable/icon",
MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
Theme = "@android:style/Theme.Holo.Light")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity, IAuthenticate
{
MobileServiceUser user;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
App.Init((IAuthenticate)this);
LoadApplication(new App());
}
public async Task<bool> AuthenticateAsync()
{
bool success = false;
try
{
if (user == null)
{
// The authentication provider could also be Facebook, Twitter, or Microsoft
user = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(this, MobileServiceAuthenticationProvider.Google, Constants.URLScheme);
if (user != null)
{
CreateAndShowDialog(string.Format("You are now logged in - {0}", user.UserId), "Logged in!");
}
}
success = true;
}
catch (Exception ex)
{
CreateAndShowDialog(ex.Message, "Authentication failed");
}
return success;
}
public async Task<bool> LogoutAsync()
{
bool success = false;
try
{
if (user != null)
{
CookieManager.Instance.RemoveAllCookie();
await TodoItemManager.DefaultManager.CurrentClient.LogoutAsync();
CreateAndShowDialog(string.Format("You are now logged out - {0}", user.UserId), "Logged out!");
}
user = null;
success = true;
}
catch (Exception ex)
{
CreateAndShowDialog(ex.Message, "Logout failed");
}
return success;
}
void CreateAndShowDialog(string message, string title)
{
var builder = new AlertDialog.Builder(this);
builder.SetMessage(message);
builder.SetTitle(title);
builder.SetNeutralButton("OK", (sender, args) => { });
builder.Create().Show();
}
}
}
就像我上面说的,我也用AAD试过了。上面的代码是针对谷歌的
这是我的Azure身份验证设置
这是我登录并访问后得到的信息
我觉得我已经尝试了很多东西。我已经记录了66.68个小时的工作,只是试图在我的应用程序中获得身份验证。。。。请有人告诉我我做错了什么!我在这里丢失了:“根据您的描述,我假设您正在使用提供的。由于您使用的是Microsoft.Azure.Mobile.Client>=4.0.0,因此对于您的移动客户端,您可以利用以下代码段通过服务器流进行日志记录:
var user = await client.LoginAsync(this, provider, "{url_scheme_of_your_app}");
你可以关注细节。此外,你需要这样做
根据手机2发出的错误信息:
托多利斯特bbservice://easyauth.callback/authorization_code=xxxxx
您似乎没有正确配置授权重定向URI。对于Azure Active Directory提供程序,您可以按照要求注册Web应用程序/API或本机应用程序。对于谷歌供应商,你可以跟随
正确配置首选标识提供程序后,您需要将应用程序添加到允许的外部重定向URL:
登录Azure门户,选择你的应用程序服务
单击“身份验证/授权”按钮,
在允许的外部重定向URL中输入ToDoList53172://easyauth.callback,并保存更改。
解决此问题的方法是不要在Url方案中使用大写字母开头。我花了两个多星期才弄明白。我不认为这是她写的,但我肯定是的。 所以是的,为了解决这个问题,我切换到了策略53172到策略53172
就这样。。。哎呀 谢谢你的回复。我知道我发布了很多信息,但在我的文章中,我确实说我已经将我允许的外部重定向URL设置为ToDoList53172://easyauth.callback我允许的外部重定向URL是ToDoList53172://easyauth.callback,在我的AndroidManifest.xml中看起来是这样的:我没有列出MainActivity.cs的代码,因为这正是我链接中的示例项目。但是是的,我的LoginAsync看起来和你写的一模一样。我会用更多的设置截图来编辑我的帖子。抱歉,我不想有一篇很长的文章。你的移动后端正在尝试将用户重定向到todolistjbbservice://easyauth.callback/authorization_code=xxxxx. 由于您已经配置了允许的外部重定向URL,我假设您需要遵循我的答案中的授权重定向URI部分,并在配置登录提供程序时按照教程检查重定向URI。哦,对不起。那张截图只是我无数次尝试中的一次。这是当时正确的授权重定向URI。明天我会更新截图以显示更新的截图。但要知道todolistjbbservice已注册为todolistjbbservice://easyauth.callback. 我刚刚记不清我做了多少版本,我的照片涵盖了所有版本。很抱歉混淆了简单的方法,我建议您通过浏览器直接访问https://{your app name}.azurewebsites.net/.auth/login/{provider name例如google或aad},并尝试检查您的登录提供商是否已成功配置。登录后,您可以访问https://{your app name}.azurewebsites.net/。
授权/我检索您的登录用户信息。是的,我也这么做了。我觉得我已经学习了很多教程,阅读了很多论坛帖子。以下是结果。再次抱歉,如果所有的URL都不匹配。我正在从一个版本的项目中获取所有截图。伙计,你在2020年救了我的命!给我你的地址,我会送你一枚金牌: