gpt4 book ai didi

azure - 向网站授予应用程序注册权限

转载 作者:行者123 更新时间:2023-12-03 03:47:55 25 4
gpt4 key购买 nike

我正在尝试从 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

当我查看 bodyTxt 时,它看起来像这样。不确定这是否是问题所在(哈希表部分): enter image description here

我尝试从 postman 那里做这件事并且有效: enter image description here

最佳答案

您必须添加-Depth参数

Specifies how many levels of contained objects are included in theJSON representation

Source.

ConvertTo-Json -Depth 100

关于azure - 向网站授予应用程序注册权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68406416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com