|
1 | 1 | ---
|
2 | 2 | title: Replace an expiring client secret in a SharePoint Add-in
|
3 | 3 | description: Add a new client secret for a SharePoint Add-in that is registered with AppRegNew.aspx.
|
4 |
| -ms.date: 09/09/2024 |
| 4 | +ms.date: 04/16/2025 |
5 | 5 | ms.localizationpriority: high
|
6 | 6 | ms.service: sharepoint
|
7 | 7 | ---
|
@@ -30,7 +30,14 @@ Ensure the following before you begin:
|
30 | 30 | - You have installed Microsoft Graph Powershell SDK: [Install the Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/installation)
|
31 | 31 | - You're a tenant administrator (or having **Application.ReadWrite.All** permission) for the Microsoft 365 tenant where the add-in was registered with the **AppRegNew.aspx** page.
|
32 | 32 |
|
33 |
| -## Generate a new secret |
| 33 | +## Understand the type of your ACS principal before renewing the secret |
| 34 | + |
| 35 | +Historically ACS principals were created as Microsoft Entra service principals having the `servicePrincipalType` set to `Legacy`. As of December 2024 the Microsoft Entra principal creation has been streamlined and ACS principals are now created as application principals in Microsoft Entra. If you browse the Microsoft Entra applications you'll now be able to see the ACS principal you've created as of December 2024. ACS principal creation typically is done using `appregnew.aspx`. |
| 36 | + |
| 37 | +> [!Important] |
| 38 | +> Due to this alternate creation the renewal of ACS principals also differs, below two chapters show both approaches, for the ACS service principals and for the ACS application principals. Ensure you use the correct approach. |
| 39 | +
|
| 40 | +## Generate a new secret - for ACS service principals, created before December 2024 |
34 | 41 |
|
35 | 42 | 1. Create a client ID variable with the following line, using the client ID of the SharePoint Add-in as the parameter:
|
36 | 43 |
|
@@ -97,6 +104,47 @@ Ensure the following before you begin:
|
97 | 104 | > [!IMPORTANT]
|
98 | 105 | > Wait at least 24 hours for the propagation of the new ClientSecret to SharePoint.
|
99 | 106 |
|
| 107 | +## Generate a new secret - for ACS application principals, created from December 2024 onwards |
| 108 | +
|
| 109 | +```PowerShell |
| 110 | +Connect-Graph -Scopes "Application.ReadWrite.All,Directory.ReadWrite.All" |
| 111 | +$applicationId = '<your client id>' # replace with your app id |
| 112 | +$appPrincipal = Get-MgApplication -Filter "AppId eq '$applicationId'" |
| 113 | +$params = @{ |
| 114 | + PasswordCredential = @{ |
| 115 | + DisplayName = "NewSecret" # Replace with a friendly name. |
| 116 | + } |
| 117 | +} |
| 118 | +$result = Add-MgApplicationPassword -ApplicationId $appPrincipal.Id -BodyParameter $params |
| 119 | +$base64Secret = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($result.SecretText)) |
| 120 | +$dtStart = $result.StartDateTime |
| 121 | +$dtEnd = $result.EndDateTime |
| 122 | +$keyCredentials = @( |
| 123 | + @{ |
| 124 | + Type = "Symmetric" |
| 125 | + Usage = "Verify" |
| 126 | + Key = [System.Text.Encoding]::UTF8.GetBytes($result.SecretText) |
| 127 | + StartDateTime = $dtStart |
| 128 | + EndDateTime = $dtEnd |
| 129 | + }, |
| 130 | + @{ |
| 131 | + Type = "Symmetric" |
| 132 | + Usage = "Sign" |
| 133 | + Key = [System.Text.Encoding]::UTF8.GetBytes($result.SecretText) |
| 134 | + StartDateTime = $dtStart |
| 135 | + EndDateTime = $dtEnd |
| 136 | + } |
| 137 | +) |
| 138 | +# Add existing valid key credentials to the $keyCredentials |
| 139 | +$appPrincipal.KeyCredentials |%{if ($_.EndDateTime -gt [DateTime]::UtcNow) {$keyCredentials += @($_)}} |
| 140 | +Update-MgApplication -ApplicationId $appPrincipal.Id -KeyCredentials $keyCredentials # Update keys |
| 141 | +$result.SecretText # Print secret text |
| 142 | +$base64Secret # Print base64 secret |
| 143 | +$result.EndDateTime # Print the end date. |
| 144 | +``` |
| 145 | + |
| 146 | +> [!IMPORTANT] |
| 147 | +> Wait at least 24 hours for the propagation of the new ClientSecret to SharePoint. |
100 | 148 |
|
101 | 149 | ## Update the remote web application in Visual Studio to use the new secret
|
102 | 150 |
|
|
0 commit comments