Sharepoint Integration

Generate ClientID and SecretKey which never expires

Create a Sharepoint App

Step 1 : Register the Add-In

  1. Log in with an admin account on the parent site, and then go to the following URL: https://sitename.sharepoint.com/sites/subsitename/_layouts/15/appregnew.aspx 
  1. Enter the following information on the page that is displayed when you first visit the URL.

    image.png


  1. Click Create. The Add-in is registered, and the following message is displayed.

    image.png

Step 2: Grant Permissions for the Add-in

Once the Add-In is registered, the next step is to set the permissions for that add-in to access the SharePoint data.

Note: The Client ID (or App ID) and client secret registered through SharePoint Online’s /_layouts/15/AppRegNew.aspx has a validity of 1 year.

Extend the validity of the App

Here are the steps to execute a PowerShell script to extend the validity of a given app's client secret by 100 years::

Step 1:  Open Windows PowerShell as administrator:

image.png

Step 2: Put the script from below and press Enter:

Note: Please paste your current SharePoint Client ID and secret key ($ClientID, $ClientSecret) (which you have generated earlier) to the script.

if (!(Get-Module AzureAD))
{
  try
  {
    Install-Module AzureAD -Confirm:$false -Force -ErrorAction Stop
    import-module AzureAD
  }
  catch
  {
    $Error[0]
  }
}

# Parameters
$ClientID = "6b78b55e-b8bf-4303-90ae-5c50efe14b94"
$ClientSecret= "NT38Q~vlknvnYk9H._8JcQ4mgsczaqpvWWj7yda0"

# Connect to AzureAD
Connect-AzureAD

# Get the Client ID
$App = Get-AzureADServicePrincipal -All $true | Where-Object {$_.AppID -eq $ClientID}

# Get the Current Expiry Date
$CurrentExpiryDate = (Get-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId).EndDate
Write-host "Current Expiry Date:" $CurrentExpiryDate -BackgroundColor Green

# Extend the validity of the App by 100 years
$StartDate = Get-Date
$EndDate = $StartDate.AddYears(100)
New-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId -StartDate $StartDate -EndDate $EndDate -Value $ClientSecret
New-AzureADServicePrincipalKeyCredential -ObjectId $App.ObjectId -StartDate $StartDate -EndDate $EndDate -Value $ClientSecret

# Get the New Expiry Date
$CurrentExpiryDate = (Get-AzureADServicePrincipalPasswordCredential -ObjectId $App.ObjectId).EndDate
Write-host "New Expiry Date:" $CurrentExpiryDate -BackgroundColor Green

image.png

Step 3: Enter credentials of user with Global Admin permissions to Office 365 tenant:

image.png

image.png

Step 4: Find expression End Date property in the output of the script:

image.png


Revision #7
Created 11 April 2024 14:50:13
Updated 16 June 2025 17:24:54