Windows Universal App 从 Microsoft 帐户身份验证中获取用户名

Windows Universal App Get username from Microsoft Account Authentication

所以我希望用户使用 Microsoft 帐户登录我的应用程序 我在 Azure 的移动服务中完成了所有设置,这就是我在应用程序中实现登录的方式:

    private async Task<bool> AuthenticateAsync()
    {
        string message;
        bool success = false;
        try
        {
            user = await App.MobileService
             .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
            message =
                string.Format("You are now signed in - {0}", user.UserId);

            success = true;
        }
        catch (InvalidOperationException)
        {
            message = "You must log in. Login Required";
        }

        var dialog = new MessageDialog(message);
        dialog.Commands.Add(new UICommand("OK"));
        await dialog.ShowAsync();
        return success;
    }

一切正常,但我从中得到的只是一个用户 ID。

我需要登录用户的姓名,谁能帮我解决这个问题?

谢谢

and I need the name of the user that logged in, can anyone help me how should I go about this

对于 UWP 应用程序,使用官方托管是不可能的 API。请参阅 MobileServiceAuthentication class here

internal async Task<MobileServiceUser> LoginAsync()
{
        string response = await this.LoginAsyncOverride();
        if (!string.IsNullOrEmpty(response))
        {
            JToken authToken = JToken.Parse(response);

            // Get the Mobile Services auth token and user data
            this.Client.CurrentUser = new MobileServiceUser((string)authToken["user"]["userId"]);
            this.Client.CurrentUser.MobileServiceAuthenticationToken = (string)authToken[LoginAsyncAuthenticationTokenKey];
        }

        return this.Client.CurrentUser;
}

官方sdk只是获取userId和MobileServiceAuthenticationToken,其他平台需要使用GetIdentitiesAsync()方法获取身份,见 or LINK

实际上已在 SSO 过程中检索到用户名信息:

所以你必须实现授权过程(基于开源代码扩展方法)并根据需要维护用户名信息。

如果你能得到用户的输入,或许你也可以调用LiveAPI:https://msdn.microsoft.com/en-us/library/office/dn659736.aspx#Requesting_info