如何从MobileServiceUser获取用户名,电子邮件等? [英] How to get user name, email, etc. from MobileServiceUser?
问题描述
经过大量挖掘,我得到了WPF应用程序通过Azure移动服务登录用户的信息.我的移动服务已连接到我已设置的Azure Active Directory.但是,当我使用MobileServiceClient.LoginAsync(...)登录用户时,MobileServiceUser UserId似乎处于无法读取的哈希中.例如,它看起来像:"Aad:X3pvh6mmo2AgTyHdCA3Hwn6uBy91rXXXXXXXXXX".这到底是什么?
After a lot of digging around I've got my WPF application signing users in via Azure Mobile Service. My Mobile Service is connected to an Azure Active Directory that I have set up. However, when I log the user in with MobileServiceClient.LoginAsync(...) the MobileServiceUser UserId is in an unreadable hash it seems. For example it looks like: "Aad:X3pvh6mmo2AgTyHdCA3Hwn6uBy91rXXXXXXXXXX". What exactly is this?
我想获取用户的显示名称以使用,但我不知道如何使用.
I'd like to grab the user's display name to use but I can't figure out how.
推荐答案
这是Azure Active Directory的用户ID.您需要创建一个服务以通过服务公开您的AAD信息,并使用从用户那里获得的访问令牌来检索其他信息.
That is the userID of Azure Active Directory. You need to create a service to expose your AAD info through a service and retrieve the additional information using the access token you get from your user.
第一:
ServiceUser user = this.User as ServiceUser;
var identities = await user.GetIdentitiesAsync();
var aad = identities.OfType<AzureActiveDirectoryCredentials>().FirstOrDefault();
var aadAccessToken = aad.AccessToken;
var aadObjectId = aad.ObjectId;
这将为您提供访问令牌和objectID,然后您需要通过AAD图形API查询信息. https://msdn.microsoft.com/library/azure/dn151678.aspx 查看样本请求部分.您应该为查询提供获得的访问令牌和objectId.
This will give you the access token and objectID , then you need to query the information through AAD graphy API. https://msdn.microsoft.com/library/azure/dn151678.aspx Look at the sample request part. You should provide the query with the access token you got and objectId.
这篇关于如何从MobileServiceUser获取用户名,电子邮件等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!