I am developing a script to create/update group/team sites from a SharePoint list. I have everything working, but I am struggling big time with authentication.
Connect-PnPOnline -Url https://client.sharepoint.com/sites/testclientsite -UseWebLogin -Scopes "Group.ReadWrite.All","Directory.Read.All"
In order to
Anytime I am switching from the list and the newly created site to apply the template, I use
Connect-PnPOnline -Url https://client.sharepoint.com/sites/sharepointlist -UseWebLogin
To connect to SP List of clients
Connect-PnPOnline -Url https://client.sharepoint.com/sites/newsite -UseWebLogin
To connect to new site to apply template.
This works amazing through the first one or two sites, then I receive a
Apply-PnPProvisioningTemplate : The remote server returned an error: (403) Forbidden.
It is somewhat random. Sometimes it will make it through one or two sites. I have also had it work through 8 or so sites before it errors out. I am assuming it has something to do with the token expiring, but I am not positive. Any help would be appreciated.