我正在尝试从 PowerShell 执行此操作: https://learn.microsoft.com/en-us/graph/api/site-post-permissions?view=graph-rest-1.0&tabs=http
POST https://graph.microsoft.com/v1.0/sites/{sitesId}/permissions
Content-Type: application/json
{
"roles": ["write"],
"grantedToIdentities": [{
"application": {
"id": "89ea5c94-7736-4e25-95ad-3fa95f62b66e",
"displayName": "Contoso Time Manager App"
}
}]
}
当我想列出权限时它可以工作。然而,当我想要发帖时,我收到了 400 错误请求。我希望这就是我生成 body 的方式?有人成功使用图形 API 和 PowerShell 授予权限吗?
$secret = "mk1_UVNxxbD991D.5i2v"
$clientid="4fcxxd9f9"
$tenantid="57fxxb68f"
$Body = @{
'tenant' = $tenantid
'client_id' = $clientid
'scope' = 'https://graph.microsoft.com/.default'
'client_secret' = $secret
'grant_type' = 'client_credentials'
}
$Params = @{
'Uri' = "https://login.microsoftonline.com/$tenantid/oauth2/v2.0/token"
'Method' = 'Post'
'Body' = $Body
'ContentType' = 'application/x-www-form-urlencoded'
}
$AuthResponse = Invoke-RestMethod @Params
$Headers = @{
'Authorization' = "Bearer $($AuthResponse.access_token)"
}
# WORKS!
$Result = Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/sites/8xx0A0/permissions' -Headers $Headers
write-host $Result
$body = @{
roles = @('Write')
grantedToIdentities = @( @{
application = @{
id = '4fc5dxx9f9'
displayName = 'KK test 7'
}
})
}
$bodyTxt = $body | ConvertTo-Json
# FAILS
$Result = Invoke-RestMethod -Uri 'https://graph.microsoft.com/v1.0/sites/810Axx5F0A0/permissions' -Headers $Headers -Body $body -Method Post
write-host $Result
最佳答案
您必须添加-Depth
参数
Specifies how many levels of contained objects are included in the JSON representation
ConvertTo-Json -Depth 100
关于azure - 向网站授予应用程序注册权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68406416/