Hey everyone! I'm trying to set up a connection to SharePoint using the PnP PowerShell module, and I'm authenticating with a certificate. Despite following all the steps correctly, I'm hitting a 401 Unauthorized error. Here's the command I'm running:
```powershell
connect-pnponline -url $ConnectionURL -ClientId $ClientId -Tenant $TenantId -CertificatePath $CertPath -CertificatePassword (ConvertTo-SecureString $CertPassword -AsPlainText -Force) -Verbose
```
The verbose output shows that it's trying to connect using Entra ID App-Only with the certificate, but I can't seem to get past the Unauthorized status.
I've also assigned all the necessary permissions and granted admin consent for both Microsoft Graph and SharePoint. Everything looks correct, but I just can't figure out what's wrong. Any advice would be greatly appreciated!
2 Answers
It sounds like you might need to double-check the SharePoint permissions. I faced a similar issue before. Make sure you run this command to grant the necessary site permissions:
```powershell
Grant-PnPAzureADAppSitePermission -AppId -DisplayName -Permissions -Site
```
You can find more info in the [documentation here](https://pnp.github.io/powershell/cmdlets/Grant-PnPAzureADAppSitePermission.html).
This is usually needed only if you're using Graph API permission for Sites.Selected, which doesn’t apply in your case.
Have you checked the output from `Get-PnPContext`? Sometimes it can give you clues about what's going wrong with the connection.
Not really, I’m not sure what to look for in the output, to be honest.
I tried that, but even after granting full control to the app, I’m still hitting a 401 error.