我需要能够获取登录用户的组成员身份,以便我可以验证他是否属于特定组。但是我收到“没有足够的权限来完成操作”。使用 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/