Skip to content

Commit 102ad80

Browse files
Merge pull request SharePoint#9203 from qianghuang94/main
Modify doc to add keys to support more scenarios
2 parents 7e021b1 + ad8daba commit 102ad80

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

docs/sp-add-ins/replace-an-expiring-client-secret-in-a-sharepoint-add-in.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Replace an expiring client secret in a SharePoint Add-in
33
description: Add a new client secret for a SharePoint Add-in that is registered with AppRegNew.aspx.
4-
ms.date: 06/21/2023
4+
ms.date: 09/13/2023
55
ms.localizationpriority: high
66
ms.service: sharepoint
77
---
@@ -25,8 +25,8 @@ Removing an expired secret from ACS before you remove it from the application co
2525

2626
Ensure the following before you begin:
2727

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 Microsoft 365 tenant where the add-in was registered with the **AppRegNew.aspx** page.
28+
- You have installed Azure Active Directory PowerShell 2.0: [Install Azure Active Directory PowerShell for Graph](/powershell/azure/active-directory/install-adv2)
29+
- You're a tenant administrator for the Microsoft 365 tenant where the add-in was registered with the **AppRegNew.aspx** page.
3030

3131
## Generate a new secret
3232

@@ -35,42 +35,36 @@ Ensure the following before you begin:
3535
```powershell
3636
$clientId = 'client id of the add-in'
3737
```
38-
1. Connect to graph with **Application.ReadWrite.All** scope:
38+
39+
1. Connect to AzureAD PowerShell.
3940
4041
```powershell
41-
Connect-MgGraph -Scopes "Application.ReadWrite.All"
42-
# login with the corresponding scope; this user should be a tenant admin or anyone granted this permission
42+
$AzureAdCred = Get-Credential
43+
Connect-AzureAD -Credential $AzureAdCred # Login to AzureAD
4344
```
4445
4546
1. Generate a new client secret with the following lines:
4647
4748
```powershell
48-
$appPrincipal = Get-MgServicePrincipal -Filter "AppId eq '$clientId'" # Get principal id by AppId
49-
50-
$params = @{
51-
PasswordCredential = @{
52-
DisplayName = "NewSecret" # Replace with a friendly name.
53-
}
54-
}
49+
$endDate = (Get-Date).AddYears(1)
50+
$app = Get-AzureADServicePrincipal -Filter "AppId eq '$clientId'"
51+
$objectId = $app.ObjectId
5552
56-
$result = Add-MgServicePrincipalPassword -ServicePrincipalId $appPrincipal.Id -BodyParameter $params # Update the secret
53+
$secret = New-AzureADServicePrincipalPasswordCredential -ObjectId $objectId -EndDate $endDate
54+
New-AzureADServicePrincipalKeyCredential -ObjectId $objectId -EndDate $endDate -Type Symmetric -Usage Verify -Value $secret.Value
55+
New-AzureADServicePrincipalKeyCredential -ObjectId $objectId -EndDate $endDate -Type Symmetric -Usage Sign -Value $secret.Value
5756
58-
$result.SecretText # Print the new secret
59-
$result.EndDateTime # Print the end date.
57+
$secret.Value
58+
$secret.EndDate # Print the end date.
6059
```
6160
6261
1. The new client secret appears on the Windows PowerShell console. Copy it to a text file. You use it in the next procedure.
6362
6463
> [!TIP]
65-
> By default, the secret lasts two years if you didn't specify the EndDateTime. You can customize by leveraging the example below to specify the EndDateTime.
64+
> By default, the secret lasts one year. You can customize by leveraging the example below to specify the EndDateTime.
6665
>
6766
> ``` powershell
68-
> $params = @{
69-
> PasswordCredential = @{
70-
> DisplayName = "NewSecret" # Replace with a firendly name.
71-
> EndDateTime = "2025-01-01T00:00:00Z" # Optional. Specify the end date you want. Using ISO 8601 format.
72-
> }
73-
> }
67+
> $endDate = (Get-Date).AddYears(2) # 2 year.
7468
> ```
7569
7670
## Update the remote web application in Visual Studio to use the new secret
@@ -80,7 +74,7 @@ Ensure the following before you begin:
8074
8175
1. Open the SharePoint Add-in project in Visual Studio, and open the **web.config** file for the web application project. In the `appSettings` section, there are keys for the client ID and client secret. The following is an example:
8276
83-
```XML
77+
```xml
8478
<appSettings>
8579
<add key="ClientId" value="your client id here" />
8680
<add key="ClientSecret" value="your old secret here" />
@@ -90,7 +84,7 @@ Ensure the following before you begin:
9084
9185
1. Change the name of the `ClientSecret` key to `SecondaryClientSecret` as shown in the following example:
9286
93-
```XML
87+
```xml
9488
<add key="SecondaryClientSecret" value="your old secret here" />
9589
```
9690
@@ -99,7 +93,7 @@ Ensure the following before you begin:
9993
10094
1. Add a new `ClientSecret` key and give it your new client secret. Your markup should now look like the following:
10195
102-
```XML
96+
```xml
10397
<appSettings>
10498
<add key="ClientId" value="your client id here" />
10599
<add key="ClientSecret" value="your new secret here" />

0 commit comments

Comments
 (0)