Azure MobileServiceClient登录同步

Azure MobileServiceClient登录同步,azure,xamarin.android,azure-mobile-services,Azure,Xamarin.android,Azure Mobile Services,我正在尝试使用Azure移动服务客户端验证我正在使用Xamarin.Android构建的应用程序。My Main活动具有以下代码: [Activity(Label = "AppName", MainLauncher = true, Icon = "@mipmap/icon")] public class MainActivity : Activity { private MobileServiceUser user; private MobileServiceClient cli

我正在尝试使用Azure移动服务客户端验证我正在使用Xamarin.Android构建的应用程序。My Main活动具有以下代码:

[Activity(Label = "AppName", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
    private MobileServiceUser user;
    private MobileServiceClient client;

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        CurrentPlatform.Init();

        client = new MobileServiceClient(Config.AppServiceUrl);

        SetContentView(Resource.Layout.Main);

        FindViewById<Button>(Resource.Id.ListOfEquipmentButton).Click += ListOfEquipmentButton_Click;
        FindViewById<Button>(Resource.Id.buttonLoginUser).Click += LoginUser;
    }

    private async Task<bool> Authenticate()
    {
        var success = false;
        try
        {

            user = await client.LoginAsync(this,
                                           MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, "https://MyAzureWebServiceSite.azurewebsites.net");
            CreateAndShowDialog(string.Format("you are now logged in - {0}",
                user.UserId), "Logged in!");

            success = true;
        }
        catch (Exception ex)
        {
            CreateAndShowDialog(ex, "Authentication failed");
        }
        return success;
    }

    public async void LoginUser(object sender, EventArgs e)
    {
        // Load data only after authentication succeeds.
        if (await Authenticate())
        {
            //Hide the button after authentication succeeds.
            FindViewById<Button>(Resource.Id.buttonLoginUser).Visibility = ViewStates.Gone;
        }
    }

    void ListOfEquipmentButton_Click(object sender, System.EventArgs e)
    {
        var intent = new Intent(this, typeof(ListOfEquipmentActivity));
        StartActivity(intent);
    }

    private void CreateAndShowDialog(Exception exception, String title)
    {
        CreateAndShowDialog(exception.Message, title);
    }

    private void CreateAndShowDialog(string message, string title)
    {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.SetMessage(message);
        builder.SetTitle(title);
        builder.Create().Show();
    }
}
[活动(Label=“AppName”,MainLauncher=true,Icon=“@mipmap/Icon”)]
公共课活动:活动
{
私人移动服务用户;
私人移动服务客户端;
创建时受保护的覆盖无效(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
CurrentPlatform.Init();
client=新的MobileServiceClient(Config.AppServiceUrl);
SetContentView(Resource.Layout.Main);
FindViewById(Resource.Id.ListofEquipment按钮)。单击+=ListofEquipment按钮\u单击;
FindViewById(Resource.Id.buttonLoginUser)。单击+=LoginUser;
}
专用异步任务身份验证()
{
var成功=false;
尝试
{
user=wait client.LoginAsync(此,
MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,“https://MyAzureWebServiceSite.azurewebsites.net");
CreateAndShowDialog(string.Format(“您现在已登录-{0}”),
UserId),“登录!”;
成功=真实;
}
捕获(例外情况除外)
{
CreateAndShowDialog(例如,“身份验证失败”);
}
回归成功;
}
公共异步void登录用户(对象发送方、事件参数)
{
//仅在身份验证成功后加载数据。
如果(等待验证())
{
//验证成功后隐藏按钮。
findviewbyd(Resource.Id.buttonLoginUser).Visibility=ViewStates.Gone;
}
}
作废设备列表按钮(对象发送者,System.EventArgs e)
{
var intent=新的intent(此,类型为(ListOfEquipmentActivity));
星触觉(意向);
}
私有void CreateAndShowDialog(异常、字符串标题)
{
CreateAndShowDialog(exception.Message,title);
}
私有void CreateAndShowDialog(字符串消息、字符串标题)
{
AlertDialog.Builder=新建AlertDialog.Builder(此);
builder.SetMessage(message);
建造商名称(名称);
builder.Create().Show();
}
}
当我运行此命令并单击布局上的登录按钮时,我得到以下信息:

我假设它正在尝试加载一个网页,我可以使用我的Azure AD凭据登录,但我没有得到登录屏幕。有什么想法吗?我的密码是FUBAR吗?任何帮助都将不胜感激

user=wait client.LoginAsync(此,MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,“”)

根据您的代码,我假设您使用的是版本4.x.x。此时,您需要正确设置应用程序的
url\u方案

  • 通过Azure门户在允许的外部重定向URL下设置
    ://easyauth.callback

  • AndroidManifest.xml
    文件下,将相关代码添加到
    application
    xml元素中

你可以关注细节

此外,您还可以尝试将
Microsoft.Azure.Mobile.Client
软件包降级为3.1.0,而无需设置上述设置