I have been tasked with extracting SharePoint List schemas for storage and I’m using PnP PowerShell module to do this, we also want to automate this so can’t use interactive login, it must be non-interactive.
I have followed PnP’s instructions to create an App Reg but left out the instructions for Adding a Platform and redirect URI.
I am trying to test locally to ensure the script works and authenticating with my user email & password as I have Full Control permissions on the website and can access the site via a browser, however I get the below error when running the script
Error occurred: AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance. The returned error contains a claims challenge. For additional info on how to handle claims related to multifactor authentication, Conditional Access, and incremental consent, see https://aka.ms/msal-conditional-access-claims. If you are using the On-Behalf-Of flow, see https://aka.ms/msal-conditional-access-claims-obo for details.
Here is my code:
$encryptedPassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $encryptedPassword)
Connect-PnPOnline -Url $targetSite -ClientId $ClientId -Credentials $creds -Verbose
We want to avoid using the other authentication option of a self-signed cert as it requires jumping over many internals hoops to get signed off and using secrets/access tokens are considered legacy methods by PnP.
I can’t see what’s blocking me from accessing the site programatically?