pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
985 stars 665 forks source link

[BUG] Connect-PnPOnline with Url ClientID ClientSecret then Get-PnPList returns error 403, but Get-PnPAADUser OK #2956

Open zzstarfish opened 3 years ago

zzstarfish commented 3 years ago

Reporting an Issue or Missing Feature

Connect-PnPOnline with Url ClientID ClientSecret (Client ID and Client Secrent are from Graph )then Get-PnPList returns error '(403) Forbidden', but if I run Get-PnPAADUser, it will return all the use information perfectly OK. As a control, I use Connect-PnPOnline -Url -WebLogin, then when I run Get-PnPList, it returns all the lists perfectly. So, there seems some issue with connet using graph to get sharepoit info.

Expected behavior

return all the list information (e.g. Title, Id, Url) of that sharepoint site.

Actual behavior

Get-PnPList : The remote server returned an error: (403) Forbidden. CategoryInfo : WriteError: (:) [Get-PnPList], WebException FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Lists.GetList

I tried about 20 times, never succeed.

Steps to reproduce behavior

To use Graph, I did the following: 1.Register App in Azure AD 2.Apply Scope Permissions for the App registered. I applied all the permission regarding sites, users. 3.Create App Secret. 4.Use a .Net Web app to Guide the User(that is me) to log on and grant permissions, to get the token, and to print on the webpage all the list info of the root site (just to make sure Graph works OK). 5.Open PowerShell as an Administrator 6.Connect-PnPOnline -Url XXXXXX -ClientSecret 'XXXXXX' -ClientId 'XXXXXXX' 7.Get-PnPList

Which version of the PnP-PowerShell Cmdlets are you using?

-PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

(you can retrieve this by executing Get-Module -Name sharepointpnppowershell* -ListAvailable) -3.24.2008.1 -3.25.2009.1 ( those two are releases after June 2020)

How did you install the PnP-PowerShell Cmdlets?

BLalanda commented 3 years ago

If you want to connect using the Microsoft Graph and Azure AD the connection string would be something like "Connect-PnPOnline -AppId $appid -AppSecret $appsecret -Url $siteUrl -Scopes Sites.FullControl.All"