0
votes

I have an Azure Function which is using PnpPowershell. I'd like to work with the users authorization. So I created a service which is getting an OAuth token from Microsoft for the user. I then give the token to the Azure Function to use it to connect via Connect-PnpOnline.

Connect-PnpOnline -AccessToken $token -Url $url
Apply-PnPProvisioningTemplate "Template.xml"

Connect-PnpOnline executes without any errors/warnings, but Apply-PnpProvisioningTemplate raises the following error: The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect.

I'd have expected the connection to be in place. I can use this token to query the MS Graph, so I'd have expected it to be valid. Does anyone have tried something similar and have an idea how to solve the issue?

Found this:

https://docs.microsoft.com/de-de/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

https://github.com/pnp/PnP-PowerShell/issues/2631

https://github.com/pnp/PnP-PowerShell/issues/2184

1

1 Answers

1
votes

Looking through the error and my understanding is that you will have to make use of the token obtained through the Sharepoint App(Sharepoint Add in) in the Connect-PNPOnline - This commandlet is specific to sharepoint.

Graph is more of a wrapper of multiple technologies - internally speak to sharepoint. So they might not have context of Sharepoint in specific.

So my suggestion would be make use of the token obtained from Sharepoint app (Sharepoint add in) - Get auth against the sharepoint URL. ( For instance : https://fabrikam.sharepoint.com/_layouts/15/OAuthAuthorize.aspx unlike in Azure App you will be making use of login.microsoftonline.com)

For detailed steps of registering and using the Sharepoint App you could refer this article