Skip to content

Commit 01e68d5

Browse files
Merge pull request SharePoint#6435 from JLRishe/patch-4
Improve key deletion script and consistency
2 parents 1416743 + f9be46b commit 01e68d5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 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: 1/18/2020
4+
ms.date: 11/10/2020
55
ms.prod: sharepoint
66
localization_priority: Priority
77
---
@@ -64,9 +64,11 @@ Ensure the following before you begin:
6464
$rand.GetBytes($bytes)
6565
$rand.Dispose()
6666
$newClientSecret = [System.Convert]::ToBase64String($bytes)
67-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
68-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
69-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
67+
$dtStart = [System.DateTime]::Now
68+
$dtEnd = $dtStart.AddYears(1)
69+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
70+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
71+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
7072
$newClientSecret
7173
```
7274
@@ -128,15 +130,21 @@ For expired client secrets, first you must delete all of the expired secrets for
128130
connect-msolservice -credential $msolcred
129131
```
130132
131-
1. Get **ServicePrincipals** and keys. Printing **$keys** returns three records. Replace each **KeyId** in **KeyId1**, **KeyId2**, and **KeyId3**. You also see the **EndDate** of each key. Confirm whether your expired key appears there.
133+
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.
132134
133135
> [!NOTE]
134136
> The **clientId** needs to match your expired **clientId**. It's recommended to delete all keys, both expired and unexpired, for this **clientId**.
135137
136138
```powershell
137139
$clientId = "27c5b286-62a6-45c7-beda-abbaea6eecf2"
138140
$keys = Get-MsolServicePrincipalCredential -AppPrincipalId $clientId
139-
Remove-MsolServicePrincipalCredential -KeyIds @("KeyId1"," KeyId2"," KeyId3") -AppPrincipalId $clientId
141+
$keys
142+
```
143+
144+
1. Remove all keys once you have confirmed that they are indeed expired.
145+
146+
```powershell
147+
Remove-MsolServicePrincipalCredential -KeyIds $keys.KeyId -AppPrincipalId $clientId
140148
```
141149
142150
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

Comments
 (0)