ServicePrincipal调用getObjectsByObjectIds需要哪些权限?

时间:2018-09-20 23:10:20

标签: c# azure-ad-graph-api

服务主体调用AD图API所需的权限是什么:通过对象ID获取对象:

POST https://graph.windows.net/ {tenantID} /getObjectsByObjectIds?api-version=1.6

我使用

设置了一个应用

应用程序许可:读取目录数据。

委派的权限:

读取目录数据 读写目录数据 阅读所有用户的完整资料 登录并阅读用户个人资料。

但是在进行API调用时,我收到了禁止访问(状态代码403):

enter image description here

我也通过以下代码获得了访问令牌:

字符串授权=“ https://login.microsoftonline.com/” +“ microsoft.com”;

        AuthenticationContext ac = new AuthenticationContext(authority);

        ClientCredential cr = new ClientCredential("Appid", "Cred");
        string OfficeUrl = "https://graph.windows.net";
        AuthenticationResult authenticationResult = ac.AcquireTokenAsync(OfficeUrl, cr).Result;
        string token = authenticationResult.AccessToken;
        // string token = this.SetAuthorizationToken();           
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

1 个答案:

答案 0 :(得分:0)

是的,这是此API所需的读取目录数据(Directory.Read.All)的正确权限。为Graph API添加所需的权限后,请确保按“授予权限”按钮,因为此权限需要管理员的同意。enter image description here