[SPO/PNP] Connect to SharePoint online using PNP and a self-signed certificate

Since the 3.0.x version of the PNP module, you don’t have the -UseWebLogin switch anymore when using Connect-PnPOnline.

So, let’s connect using a self-signed certificate instead.

Here’s how to do it:

  1. Create a self-signed certificate:

Note: you need to have the PNP.PowerShell module installed before running the below cmdlets. 

This command creates:

pnpappcert.pfx: the private certificate used by your script

pnpappcert.cer: the public certificate to upload to Entra ID

Note: The password is required later to use the .pfx

 

2. Register an app in Entra ID 

  • Go to: https://entra.microsoft.com
  • Navigate to “App registrations” > “New registration”

Fill in:

Name: PnPApp

Supported account types: Single tenant is OK

Redirect URI: Leave blank for now

Click Register

 

3. Upload the Public Certificate to the App

 

In the app registration panel:

Go to Certificates & secrets

Choose Certificates (Upload) → Upload pnpappcert.cer

 

4. Assign API Permissions

 

  • In the app registration:

    • Go to API permissions

    • Click Add a permission

    • Choose SharePoint > Application permissions

    • Check:

      • Sites.Read.All

      • Sites.FullControl.All (if needed)

    • Click Add permissions

  • Then click Grant admin consent

Note: you can grant additional permissions. Here’s a screenshot of what I used:

App Permissions

 

5. Connect using you certificate and APPId

 

Enjoy!