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

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

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

问题

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

这是我执行的代码:

  1. $tenant = '<SNIP>'
  2. $client_id = '<SNIP>'
  3. $client_secret = '<SNIP>'
  4. $scope = [System.Web.HttpUtility]::UrlEncode('https://graph.microsoft.com/.default')
  5. $url = "https://login.microsoftonline.com/$tenant/oauth2/v2.0/token"
  6. $Body = "client_id=$client_id&scope=$scope&client_secret=$client_secret&grant_type=client_credentials"
  7. $response = Invoke-RestMethod $url -Method Post -Body $Body -Headers @{ 'Content-Type'='application/x-www-form-urlencoded' }
  8. $token = $response.access_token
  9. Connect-MgGraph -AccessToken $token
  10. Get-MgUserEvent -UserId '17160c5f-dd86-46cc-92b8-54d6e94861e6'

输出:

  1. .\Calendar.ps1
  2. Welcome To Microsoft Graph!
  3. Get-MgUserEvent : Access is denied. Check credentials and try again.
  4. In C:\Users\SYSTOLA-rk\Calendar.ps1:15 Zeichen:1
  5. + Get-MgUserEvent -UserId '17160c5f-dd86-46cc-92b8-54d6e94861e6'
  6. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. + CategoryInfo : InvalidOperation: ({ UserId = 1716..., Property = }:<f__AnonymousType39`7) [Get-MgUserEvent_List1], RestException`1
  8. + 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:

  1. $tenant = &#39;&lt;SNIP&gt;&#39;
  2. $client_id = &#39;&lt;SNIP&gt;&#39;
  3. $client_secret = &#39;&lt;SNIP&gt;&#39;
  4. $scope = [System.Web.HttpUtility]::UrlEncode(&#39;https://graph.microsoft.com/.default&#39;)
  5. $url = &quot;https://login.microsoftonline.com/$tenant/oauth2/v2.0/token&quot;
  6. $Body = &quot;client_id=$client_id&amp;scope=$scope&amp;client_secret=$client_secret&amp;grant_type=client_credentials&quot;
  7. $response = Invoke-RestMethod $url -Method Post -Body $Body -Headers @{&#39;Content-Type&#39;=&#39;application/x-www-form-urlencoded&#39;}
  8. $token = $response.access_token
  9. Connect-MgGraph -AccessToken $token
  10. Get-MgUserEvent -UserId &#39;17160c5f-dd86-46cc-92b8-54d6e94861e6&#39;

Output:

  1. .\Calendar.ps1
  2. Welcome To Microsoft Graph!
  3. Get-MgUserEvent : Access is denied. Check credentials and try again.
  4. In C:\Users\SYSTOLA-rk\Calendar.ps1:15 Zeichen:1
  5. + Get-MgUserEvent -UserId &#39;17160c5f-dd86-46cc-92b8-54d6e94861e6&#39;
  6. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. + CategoryInfo : InvalidOperation: ({ UserId = 1716..., Property = }:&lt;&gt;f__AnonymousType39`7) [Get-MgUserEvent_List1], RestException`1
  8. + 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:

确定