Azure AD Graph API 未返回创建用户的用户 GUID

Azure AD Graph API not returning User GUID for Create User

这是我发送请求所采用的 post 格式的 URL。

https://graph.windows.net/myorganization/users?api-version=1.6

我还附加了带有访问令牌的身份验证 header 值 Bearer。 request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

我在 body

中请求这些元素

Content-type: application/json

{
  "accountEnabled": true,
  "displayName": "displayName-value",
  "mailNickname": "mailNickname-value",
  "userPrincipalName": "upn-value@tenant-value.onmicrosoft.com",
  "passwordProfile" : {
    "forceChangePasswordNextSignIn": true,
    "password": "password-value"
  }
}

来源:Link

这是我收到的回复

{StatusCode: 201, ReasonPhrase: 'Created', Version: 1.1, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
{
  Cache-Control: no-cache
  Date: Wed, 30 Aug 2017 19:11:40 GMT
  Pragma: no-cache
  Location: https://graph.windows.net/metadata/directoryObjects/metadata/Microsoft.DirectoryServices.User
  Server: Microsoft-IIS/8.5
  ocp-aad-diagnostics-server-name: servername
  request-id: req id
  client-request-id: client request id
  x-ms-dirapi-data-contract-version: 1.6
  ocp-aad-session-key: some random keys
  X-Content-Type-Options: nosniff
  DataServiceVersion: 3.0;
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Access-Control-Allow-Origin: *
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  X-Powered-By: ASP.NET
  Duration: 4425304
  Content-Length: 1271
  Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8
  Expires: -1
}}

但我无法找到上面来源 link 中提到的任何用户数据/GUID。

如有任何帮助,我们将不胜感激。

你在混淆 Azure Active Directory Graph with Microsoft Graph API。这是两个不同的 API。虽然 Microsoft Graph API 正在取代 AAD Graph,但它们具有不同的方法和有效负载,因此两者之间的代码不可互换。他们还使用不同的令牌。

当您 creating a user 时,您会希望 POST JSON 有效负载到 https://graph.microsoft.com/v1.0/users 而不是 https://graph.windows.net/...

您还需要确保请求 User.ReadWrite.All scope and that you're either using a Global Administrator account or have had a Global Admin go through the Admin Consent 流程。这将为您提供在目录中创建用户所需的权限。

您发布的回复仅包含 headers。还有一个JSONbody(headers包括Content-Length: 1271)。

正如您在the link you posted中所见,响应body包含新用户信息,包括用户的objectId,因此您应该解析body。