Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect-MgGraph app-only authentication - Access is denied errors #1639

Closed
SPNass opened this issue Nov 16, 2022 · 1 comment
Closed

Connect-MgGraph app-only authentication - Access is denied errors #1639

SPNass opened this issue Nov 16, 2022 · 1 comment

Comments

@SPNass
Copy link

SPNass commented Nov 16, 2022

Hi Gents,

I'm trying to use the Graph SDK to manage organization contacts for internal employees via a runbook.
I see from the MS documentation that app-only authentication is supported:
https://learn.microsoft.com/en-us/powershell/microsoftgraph/app-only?view=graph-powershell-1.0&tabs=powershell

Therefore, I’m connecting as follows:

$Connection = Get-AutomationConnection -Name “AzureRunAsConnectionGraph”
Connect-MgGraph -ClientID $Connection.ApplicationId -TenantId $Connection.TenantId -CertificateThumbprint $Connection.CertificateThumbprint
$context = Get-MgContext
$context.Scopes

Here is the output:

Welcome To Microsoft Graph!
TeamMember.Read.All
User.ReadWrite.All
Group.Read.All
Directory.Read.All
GroupMember.Read.All
Team.ReadBasic.All
MailboxSettings.Read
Contacts.ReadWrite
Mail.Send
MailboxSettings.ReadWrite
Contacts.Read

Despite using the app-only authentication and having "Contacts.ReadWrite" permission, I’m getting "access is denied" errors on all below commands:

  • Get-MgUserContactFolder
    -$folderStaffDirectory = Get-MgUserContactFolder -UserId $Mbx.UserPrincipalName | Where-Object {$_.DisplayName -eq $folderName}
  • New-MgUserContactFolder
    New-MgUserContactFolderContact -UserId $Mbx.UserPrincipalName -BodyParameter $params -ContactFolderId $folderStaffDirectory.Id -DisplayName $Contact.DisplayName -CompanyName $Contact.CompanyName -Department $Contact.Department -JobTitle $Contact.JobTitle -PersonalNotes $OrgNotes -MobilePhone $Contact.Mobile
  • Get-MgUserContactFolderContact
    [array]$ContactsInMbx = Get-MgUserContactFolderContact -UserId $Mbx.UserPrincipalName -ContactFolderId $folderStaffDirectory.Id -All
  • New-MgUserContactFolderContact
    $folderStaffDirectory = New-MgUserContactFolder -UserId $Mbx.UserPrincipalName -BodyParameter $paramsFolder

Error example:
Get-MgUserContactFolder : Access is denied. Check credentials and try again. At line:91 char:2 + $folderStaffDirectory = Get-MgUserContactFolder -UserId $Mbx.User ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ({ UserId = conf..., Property = }:<>f__AnonymousType317) [Get-MgUserContactFolder_List1], RestException1 + FullyQualifiedErrorId : ErrorAccessDenied,Microsoft.Graph.PowerShell.Cmdlets.GetMgUserContactFolder_List1

Is there anything wrong ?
Please feel free whether you need more details.

Thanks in advance.
Cheers,
Patrick

@ghost ghost added the ToTriage label Nov 16, 2022
@ghost ghost added this to Issues to triage in Graph SDK - Triage Nov 16, 2022
@peombwa
Copy link
Member

peombwa commented Nov 17, 2022

Thanks for following up on this.

Please open a question/ticket at https://developer.microsoft.com/en-us/graph/support for assistance around permissions and API related issues. Permission validation is handled by the API and not the module.

You should also include the request-id and date response headers of the failing request in the question/ticket you open at https://developer.microsoft.com/en-us/graph/support. See https://learn.microsoft.com/en-us/powershell/microsoftgraph/troubleshooting?view=graph-powershell-1.0#using--debug for details on how to access the headers.

@peombwa peombwa closed this as completed Nov 17, 2022
Graph SDK - Triage automation moved this from Issues to triage to Closed Nov 17, 2022
@ghost ghost removed the ToTriage label Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

2 participants