Connect-PnPOnline Error: "Token request failed"

Hi friends,

I was working on PnP Powershell and while trying to connect it to the site via AppId & AppSecret or ClientId & ClientSecret I started getting the error: "Connect-PnPOnline: Token request failed". After a lot of googling, I got the solution or say the root cause of the issue.

Connect-PnPOnline Error: "Token request failed" @Connect-PnPOnline Error: "Token request failed" @SharePointWidgets.com


Find out the expiration dates of the SharePoint Add-ins installed to the Office 365 tenancy

When a SharePoint add-in is created, the ClientId and ClientSecret is valid for the duration of 1 year, after that you need to renew the ClientSecret. To verify the valid keys in your tenant execute the below code

Step 1: Install the MSOnline module

To get the information, you need to install the MSOnline module. To install open the Powershell application with the Administrator rights and execute the below command

Install-Module -Name MSOnline


This will install the necessary module

Step 2: Check for the valid ClientId's

Execute the below code in the Powershell. This will return all the valid ClientID's. Below script will filter the following
  • All Microsoft's own application
  • All non-SharePoint Add-ins

If the output of the above contains your key, then you can check the validity of it. If not then it must have expired.

Step 3: Generate new ClientSecret for SharePoint Add-in

The below code will help you to generate the new ClientSecret for the specific Client ID. 


Hope this will help you to quickly resolve the issue 

Happy Coding
#Microsoft #Powershell #SharePointAddin #SharePointWidgets


Comments

Popular posts from this blog

Rename Folder using Microsoft Flow / Power Automate in a Document Library in SharePoint Online

Power Automate: How to Add "New Line" to the text in SharePoint multiline text field

Power Automate: Rename file in SharePoint Online