azure - 尝试使用 Azure AD Graph API 获取登录用户的组成员身份时出现权限不足错误

标签 azure azure-active-directory azure-ad-graph-api

我需要能够获取登录用户的组成员身份,以便我可以验证他是否属于特定组。但是我收到“没有足够的权限来完成操作”。使用 Azure AD 图形 API 客户端库的异常。

我是订阅的共同管理员,我创建了一个新的 Azure AD 应用程序来针对默认目录进行身份验证,并配置了“其他应用程序的权限”部分,如下面的屏幕截图所示。

Azure AD Application Configuration

我能够获取登录的用户详细信息,但是当我尝试调用 MemberOf 函数时,我收到上述异常。请让我知道我在这里缺少什么。提前致谢!

string objectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; // object id of the signed in user

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); 

IUser user = await client.Users.GetByObjectId(objectId).ExecuteAsync();
var userFetcher = (IUserFetcher)user; // able to fetch the signed in user

IPagedCollection<IDirectoryObject> pagedCollection = await userFetcher.MemberOf.ExecuteAsync(); // getting error here - "Insufficient privileges to complete the operation."               

最佳答案

这里的问题是我选择了“个人范围”之外的权限(以登录用户身份访问目录,读取目录数据)。

因此,需要获得与目录关联的订阅的服务管理员的同意。一旦管理员登录应用程序并批准同意屏幕,代码应该停止给出权限不足的异常。

关于azure - 尝试使用 Azure AD Graph API 获取登录用户的组成员身份时出现权限不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777062/

相关文章:

azure - IIS 重写规则在 Azure 生产中不起作用

asp.net - 我的 Azure 网站未显示在搜索引擎上

c# - 通过应用程序洞察中的端到端事务跟踪 azure redis

javascript - adal.js 适用于不同的后端

Azure oauth v2.0 interaction_required 错误与受信任的 ip 和 MFA

c# - 如何在 EF code-first 和 Azure 中创建默认约束?

azure - 应用程序和用户的 AAD AppRoles allowedMemberTypes

azure - 使用 Azure AD 测试应用程序

azure-ad-graph-api - 如何在microsoft graph api中获取用户日历事件

azure - 在 Azure AD Multi-Tenancy 环境中是否始终需要管理员同意?