pnp / PnP-PowerShell

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

Connect-PnPOnline -AccessToken $Access_Token -Url $TenantUrl (401 after connection) #2846

Closed babasaheb-ghaytadkar closed 3 years ago

babasaheb-ghaytadkar commented 3 years ago

Reporting an Issue or Missing Feature

I have created an Azure AD App, with permission provided for SharePoint as per below screenshot image

Using below command to connect Connect-PnPOnline -AccessToken $AAd_AccessToken -Url https://tenant-admin.sharepoint.com -ReturnConnection -Verbose

I am able to connect and getting context back, however any command running after this failed to execute with below error PS C:\Windows\system32> Get-PnPWeb Get-PnPWeb : The remote server returned an error: (401) Unauthorized. At line:1 char:1

Same is not case with any normal SharePoint site, apart from the admin center / Tenant URL.

Expected behavior

Get-PnPWeb should work the way it works for normal sites e.g. as below PS C:\Windows\system32> Connect-PnPOnline -AccessToken $AAd_AccessToken -Url https://tenantname.sharepoint.com/sites/Baba PS C:\Windows\system32> Get-PnPWeb

Title ServerRelativeUrl Id


Baba /sites/Baba 9417b847-39be-45ae-8309-***

Actual behavior

image

Steps to reproduce behavior

  1. Register Azure AD App, with the permissions mentioned in the issue details
  2. Get Access Token using resource https://graph.microsoft.com
  3. Use below command to connect to SharePoint online Connect-PnPOnline -AccessToken $AAd_AccessToken -Url https://tenant-admin.sharepoint.com -ReturnConnection -Verbose

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

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

3.21.20 SharePointPnPPowerShellOnline..

How did you install the PnP-PowerShell Cmdlets?

babasaheb-ghaytadkar commented 3 years ago

Issue was to Access Token and the resource used to get the token. After changing resource value to get token for tenant, things are working fine.