![](/img/trans.png)
[英]Get UserName in a Windows 10 C# UWP Universal Windows app
[英]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。
并且我需要登录用户的名字,有人可以帮助我该怎么做吗?
谢谢
并且我需要登录的用户名,任何人都可以帮助我该怎么做
对于UWP应用,使用官方托管API是不可能的。 请参阅此处的 MobileServiceAuthentication
类
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()
方法获取身份,请参阅如何从MobileServiceUser获取用户名,电子邮件等? 或链接
因此,您必须实现身份验证过程(根据开放源代码扩展方法)并根据需要维护用户名信息。
如果您可以获取用户的输入,也许您也可以调用Live API: https : //msdn.microsoft.com/en-us/library/office/dn659736.aspx#Requesting_info
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.