graph beta / groups / $ id / channels此请求已被拒绝授权

时间:2017-12-14 14:26:30

标签: azure microsoft-graph azure-api-management

我希望从天蓝色小组中获取所有频道。 查询组工作并返回所有azure组。但是,查询组通道会导致错误

Authorization has been denied for this request

代码:

$appID = "f9....22"
$appSecret="FH..8="
$tokenAuthURI = "https://login.microsoftonline.com/c6...59/oauth2/token"
$requestBody = "grant_type=client_credentials" + 
            "&client_id=$appID" +
            "&resource=https://graph.microsoft.com" +
            "&client_secret=$appSecret"
$tokenResponse = Invoke-RestMethod -Method Post -Uri $tokenAuthURI -body $requestBody -ContentType "application/x-www-form-urlencoded"
$accessToken = $tokenResponse.access_token
$groupsListURI = "https://graph.microsoft.com/beta/groups?`$filter=groupTypes/any(c:c+eq+`'Unified`')"
$graphResponse = Invoke-RestMethod -Method Get -Uri $groupsListURI -Headers @{"Authorization"="Bearer $accessToken"}
$TeamsList = @()
foreach ($group in $graphResponse.value)
        {
            if($group.groupTypes -eq "Unified") {
                $id= $group.id
                Try
                {
                    $url = "https://graph.microsoft.com/beta/groups/$id/channels"
                    $team = Invoke-RestMethod -Method Get -Uri $url -Headers @{"Authorization"="Bearer $accessToken"}
                    "Channel count for " + $group.displayName + " is " + $team.value.id.count
                }
                Catch
                {
                    $result = $_.Exception.Response.GetResponseStream()
                    $reader = New-Object System.IO.StreamReader($result)
                    $reader.BaseStream.Position = 0
                    $reader.DiscardBufferedData()
                    $reader.ReadToEnd()
                    $team = $null
                }
}
}

捕获结果是""

{
  "error": {
    "code": "",
    "message": "Authorization has been denied for this request.",
    "innerError": {
      "request-id": "7c...89",
      "date": "2017-12-14T14:19:39"
    }
  }
}

THX

更新

还尝试添加$ scope或$ scope2。相同的结果

$scope = "https://graph.microsoft.com/Group.ReadWrite.All https://graph.microsoft.com/Group.Read.All https://graph.microsoft.com/User.ReadBasic.All https://graph.microsoft.com/Directory.AccessAsUser.All https://graph.microsoft.com/Directory.Read.All"
$scope2 = "Group.ReadWrite.All Group.Read.All Directory.Read.All Directory.AccessAsUser.All User.ReadBasic.All"


$requestBody = "grant_type=client_credentials" + 
            "&client_id=$appID" +
            "&resource=https://graph.microsoft.com" +
            "&client_secret=$appSecret" +
            "&scope=$scope2"

0 个答案:

没有答案