如何从MobileServiceUser获取用户名

如何从MobileServiceUser获取用户名

本文介绍了如何从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.aspxLook at the sample request part. You should provide the query with the access token you got and objectId.

这篇关于如何从MobileServiceUser获取用户名、邮箱等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 11:41