![](/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.