Azure active directory Can';t在MS Graph中展开新创建的开放扩展

Azure active directory Can';t在MS Graph中展开新创建的开放扩展,azure-active-directory,Azure Active Directory,TLDR版本:这是由于在调用Graph之前未对Graph查询字符串进行编码造成的-这不是API问题 我已经为特定用户创建了一个新的开放扩展。我可以读取用户,或者专门读取开放扩展名,但我不能使用$expand在一次调用中同时返回具有开放扩展名的用户 https://graph.microsoft.com/v1.0/users?$expand=extensions 我正在对AAD使用应用程序身份验证(带有一个秘密),这可能与此有关,也可能与此无关。我发现的每个示例都使用Graph Explorer

TLDR版本:这是由于在调用Graph之前未对Graph查询字符串进行编码造成的-这不是API问题

我已经为特定用户创建了一个新的开放扩展。我可以读取用户,或者专门读取开放扩展名,但我不能使用$expand在一次调用中同时返回具有开放扩展名的用户

https://graph.microsoft.com/v1.0/users?$expand=extensions
我正在对AAD使用应用程序身份验证(带有一个秘密),这可能与此有关,也可能与此无关。我发现的每个示例都使用Graph Explorer中的/v1.0/me快捷方式

编辑:我很快得到了一个没有考虑到这一点的答案。MS Graph Explorer仅允许通过用户帐户进行身份验证,对我没有帮助

我可以始终添加、读取和删除扩展名。唯一的问题是在读取时扩展扩展属性


$uri = "https://graph.microsoft.com/v1.0/users/user@domain.com.au/extensions"

$body = '{
    "@odata.type":"microsoft.graph.openTypeExtension",
    "extensionName":"au.com.domain.customAttributes",
    "shoesize":"large"
}'

$query = Invoke-RestMethod -Method Post -Uri $uri -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop

#Modify an existing custom attribute
$uri = "https://graph.microsoft.com/v1.0/users/user@domain.com.au/extensions/au.com.domain.customAttributes"

$body = '{
    "shoesize":"small"
}'

$query = Invoke-RestMethod -Method Patch -Uri $uri -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop

## Read user without extension attributes
$uri = "https://graph.microsoft.com/v1.0/users/user@domain.com.au"
$user = Invoke-RestMethod -Method Get -Uri $uri -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop
Write-Host $user

## Read extension attributes only in separate call
$uri = "https://graph.microsoft.com/v1.0/users/user@domain.com.au/extensions/au.com.domain.customAttributes"
$customAttributes = Invoke-RestMethod -Method Get -Uri $uri -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop
Write-Host $customAttributes

## Delete a custom extention
$uri = "https://graph.microsoft.com/v1.0/users/user@domain.com.au/extensions/au.com.domain.customAttributes"
$customAttributes = Invoke-RestMethod -Method DELETE -Uri $uri -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop

Write-Host $customAttributes
我需要能够使用过滤器从55000名用户中获取100名用户,包括他们所有的开放扩展属性

编辑:我怀疑这可能是一个与查询参数相关的问题,我想在重写问题之前,我会先考虑一下这个问题

例如:

$uri = "https://graph.microsoft.com/v1.0/users"
$users = Invoke-RestMethod -Method Get -Uri $uri -Headers @{Authorization = "Bearer $token"}  -ContentType "application/json" -ErrorAction Stop 
这为我的租户提供了前100个用户。添加任何查询参数都会中断请求。我得到一个400错误,即使Graph Explorer中的同一个图形调用给出了有意义的响应

我正在使用powershell中的Invoke RestMethod调用Graph。。。我怀疑我需要尝试另一种调用方法,或者尝试传递额外的参数来调用RestMethod

但是我不能使用$expand返回具有开放扩展名的用户 一通电话

扩展显示在扩展集合中的Microsoft Graph中。因此,您可以使用$expand在一次调用中同时返回具有开放扩展名的用户

https://graph.microsoft.com/v1.0/users?$expand=extensions
我为一个用户创建了相同的扩展。我可以在回复中找到它

更新:

我尝试了客户端凭据流,它也可以工作。下面是详细的步骤

  • 注册应用程序并授予User.ReadWrite.All权限,请记住授予管理员许可
  • 2.获取访问令牌

    3.使用访问令牌调用api

    更新:使用powershell运行它


    但是发送URI:“给了我一个错误的请求。我可能不太清楚这个问题,但我确实尝试过使用$expand。您是否在您的环境中通过secret进行身份验证?给出400错误(错误请求)。@DavidVernon您不能在此处指定用户,请尝试
    https://graph.microsoft.com/v1.0/users?$expand=extensions
    也会出现400错误!我正在使用一个应用程序进行身份验证,我已确保该应用程序具有user.readwriteall.all,符合我尝试使用客户端凭据流的@DavidVernon,并且它也可以工作,请参阅我的更新答案。