Microsoft Graph "Access is denied. Check credentials and try again" in PowerShell

huangapple go评论92阅读模式
英文:

Microsoft Graph "Access is denied. Check credentials and try again" in PowerShell

问题

无法列出日历中的事件,通过MS Graph API:调用结果显示“拒绝访问”。切换到原始HTTP也导致403错误。我能够通过向/events端点发送POST请求来创建事件。

这是我执行的代码:

$tenant = '<SNIP>'
$client_id = '<SNIP>'
$client_secret = '<SNIP>'
$scope = [System.Web.HttpUtility]::UrlEncode('https://graph.microsoft.com/.default')
$url = "https://login.microsoftonline.com/$tenant/oauth2/v2.0/token"
$Body = "client_id=$client_id&scope=$scope&client_secret=$client_secret&grant_type=client_credentials"

$response = Invoke-RestMethod  $url -Method Post -Body $Body -Headers @{ 'Content-Type'='application/x-www-form-urlencoded' }
$token = $response.access_token 

Connect-MgGraph -AccessToken  $token

Get-MgUserEvent -UserId  '17160c5f-dd86-46cc-92b8-54d6e94861e6'

输出:

.\Calendar.ps1
Welcome To Microsoft Graph!
Get-MgUserEvent : Access is denied. Check credentials and try again.
In C:\Users\SYSTOLA-rk\Calendar.ps1:15 Zeichen:1
+ Get-MgUserEvent -UserId  '17160c5f-dd86-46cc-92b8-54d6e94861e6'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ UserId = 1716..., Property =  }:<f__AnonymousType39`7) [Get-MgUserEvent_List1], RestException`1
    + FullyQualifiedErrorId : ErrorAccessDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgUserEvent_List1

这是Azure中为该应用程序配置的权限(我没有发布图像的声誉):App Permissions

英文:

I am unable to list events in a calendar via MS Graph API: calls result in "Access is denied". Switching to raw HTTP results in error 403 as well. I am able to create an event via a POST to /events endpoint, though.

This is the code I am executing:

$tenant = &#39;&lt;SNIP&gt;&#39;
$client_id = &#39;&lt;SNIP&gt;&#39;
$client_secret = &#39;&lt;SNIP&gt;&#39;
$scope = [System.Web.HttpUtility]::UrlEncode(&#39;https://graph.microsoft.com/.default&#39;) 
$url = &quot;https://login.microsoftonline.com/$tenant/oauth2/v2.0/token&quot;
$Body = &quot;client_id=$client_id&amp;scope=$scope&amp;client_secret=$client_secret&amp;grant_type=client_credentials&quot;

$response = Invoke-RestMethod  $url -Method Post -Body $Body -Headers @{&#39;Content-Type&#39;=&#39;application/x-www-form-urlencoded&#39;}
$token = $response.access_token 

Connect-MgGraph -AccessToken  $token

Get-MgUserEvent -UserId  &#39;17160c5f-dd86-46cc-92b8-54d6e94861e6&#39;

Output:

.\Calendar.ps1
Welcome To Microsoft Graph!
Get-MgUserEvent : Access is denied. Check credentials and try again.
In C:\Users\SYSTOLA-rk\Calendar.ps1:15 Zeichen:1
+ Get-MgUserEvent -UserId  &#39;17160c5f-dd86-46cc-92b8-54d6e94861e6&#39;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ UserId = 1716..., Property =  }:&lt;&gt;f__AnonymousType39`7) [Get-MgUserEvent_List1], RestException`1
    + FullyQualifiedErrorId : ErrorAccessDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgUserEvent_List1

Here are the permissions in Azure configured for the app (I lack reputation for posting images): App Permissions

答案1

得分: 0

问题出在我们发现的是,Calendars.ReadBasic.All 权限与其他 Calendar 权限发生了冲突。移除这个权限解决了错误。

英文:

The issue as we found is that the Calendars.ReadBasic.All permission was causing a conflict with the other Calendar permissions. Removing this permission resolved the error

huangapple
  • 本文由 发表于 2023年2月16日 05:51:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465767.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定