You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: 06/13/2022
4
+
ms.date: 06/21/2023
5
5
ms.prod: sharepoint
6
6
ms.localizationpriority: high
7
7
---
8
8
9
9
# Replace an expiring client secret in a SharePoint Add-in
10
10
11
-
Client secrets for SharePoint Add-ins that are registered by using the AppRegNew.aspx page expire after one year. This article explains how to add a new secret for the add-in, and how to create a new client secret that is valid for three years.
11
+
Client secrets for SharePoint Add-ins that are registered by using the AppRegNew.aspx page expire after one year. This article explains how to add a new secret for the add-in, and how to create a new client secret that is valid for a customized date.
12
12
13
13
> [!NOTE]
14
14
> This article is about SharePoint Add-ins that are distributed through an organization catalog and registered with the AppRegNew.aspx page. If the add-in is registered on the Seller Dashboard, see [Create or update client IDs and secrets in the Seller Dashboard](/office/dev/store/create-or-update-client-ids-and-secrets).
@@ -25,72 +25,50 @@ Removing an expired secret from ACS before you remove it from the application co
25
25
26
26
Ensure the following before you begin:
27
27
28
-
- Microsoft Online Services Sign-In Assistant is installed on the development computer.
29
-
- You can connect to Office 365 with PowerShell: [Connect to Office 365 PowerShell](/office365/enterprise/powershell/connect-to-office-365-powershell)
30
-
- You're a tenant administrator for the Office 365 tenant (or a farm administrator on the farm) where the add-in was registered with the AppRegNew.aspx page.
28
+
- You have installed Microsoft Graph Powershell SDK: [Install the Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/installation)
29
+
- You're a tenant administrator (or having `Application.ReadWrite.All` permission) for the Office 365 tenant where the add-in was registered with the AppRegNew.aspx page.
31
30
32
-
## Find out the expiration dates of the SharePoint Add-ins installed to the Office 365 tenancy
31
+
## Generate a new secret
33
32
34
-
1.Open Windows PowerShell and run the following cmdlet:
33
+
1.Create a client ID variable with the following line, using the client ID of the SharePoint Add-in as the parameter.
35
34
36
35
```powershell
37
-
Connect-MsolService
36
+
$clientId = 'client id of the add-in'
38
37
```
39
-
40
-
1. At the sign-in prompt, enter tenant-administrator (or farm administrator) credentials for the Office 365 tenancy or farm where the add-in was registered with AppRegNew.aspx.
41
-
1. Generate a report that lists each add-in and the date that its secret expires with the following lines. Note the following about this code:
42
-
43
-
- It first filters out Microsoft's own applications, add-ins still under development (and a now-deprecated type of add-in that was called autohosted).
44
-
- From the remainder, it filters out non-SharePoint add-ins and add-ins that use asymmetric keys, such as workflows.
38
+
2. Connect to graph with `Application.ReadWrite.All` scope.
Connect-MgGraph -Scopes "Application.ReadWrite.All" # Login with corresponding scope. Should be tenant admin or anyone have the permission.
62
42
```
63
-
64
-
1. Open the file C:\temp\appsec.csv to see the report. Leave the Windows PowerShell window open for the next procedure, if any of the secrets are near expiration.
65
-
66
-
## Generate a new secret
67
-
68
-
1. Create a client ID variable with the following line, using the client ID of the SharePoint Add-in as the parameter.
43
+
3. Generate a new client secret with the following lines:
69
44
70
45
```powershell
71
-
$clientId = 'client id of the add-in'
72
-
```
46
+
$appPrincipal = Get-MgServicePrincipal -Filter "AppId eq '$clientId'" # Get principal id by AppId
47
+
48
+
$params = @{
49
+
PasswordCredential = @{
50
+
DisplayName = "NewSecret" # Replace with a firendly name.
51
+
}
52
+
}
73
53
74
-
1. Generate a new client secret with the following lines:
1. The new client secret appears on the Windows PowerShell console. Copy it to a text file. You use it in the next procedure.
60
+
4. The new client secret appears on the Windows PowerShell console. Copy it to a text file. You use it in the next procedure.
91
61
92
62
> [!TIP]
93
-
> By default, the add-in secret lasts one year. You can set this to a shorter or longer by using the **-EndDate** parameter on the three calls of the **New-MsolServicePrincipalCredential** cmdlet.
63
+
> By default, the secret lasts two years if you didn't specifiy the EndDateTime. You can customize by leveraging the example below to specify the EndDateTime.
64
+
> ``` powershell
65
+
> $params = @{
66
+
> PasswordCredential = @{
67
+
> DisplayName = "NewSecret" # Replace with a firendly name.
68
+
> EndDateTime = "2025-01-01T00:00:00Z" # Optional. Specify the end date you want. Using ISO 8601 format and is always in UTC time.
69
+
> }
70
+
> }
71
+
> ```
94
72
95
73
## Update the remote web application in Visual Studio to use the new secret
96
74
@@ -133,55 +111,6 @@ Ensure the following before you begin:
133
111
1. If you changed to a new TokenHelper file, rebuild the project.
134
112
1. Republish the web application.
135
113
136
-
## Create a client secret that is valid for three years
137
-
138
-
For expired client secrets, first you must delete all of the expired secrets for a given **clientId**. You then create a new one with MSO PowerShell, wait at least 24 hours, and test the app with the new **clientId** and **ClientSecret** key.
139
-
140
-
1. Connect to MSOnline using the tenant admin user with the following markup using SharePoint Windows PowerShell.
141
-
142
-
```powershell
143
-
import-module MSOnline
144
-
$msolcred = get-credential
145
-
connect-msolservice -credential $msolcred
146
-
```
147
-
148
-
1. Get **ServicePrincipals** and keys. Printing **$keys** returns three records. You also see the **EndDate** of each key. Confirm whether your expired key appears there.
149
-
150
-
> [!NOTE]
151
-
> The **clientId** needs to match your expired **clientId**. It's recommended to delete all keys, both expired and unexpired, for this **clientId**.
1. Generate a new **ClientSecret** for this **clientID**. It uses the same **clientId** as set in the preceding step. The new **ClientSecret** is valid for three years.
0 commit comments