Skip to content

Commit 43e3da3

Browse files
authored
Improve key deletion script and consistency
This proposed change fixes a few issues in the document: - There was an inconsistency between the one-year client secret script and the three-year one - namely that the first adds 1 year to the current date on three different lines, while the second calculates the end date first, and uses it. I have made the first script consistent with the second, which is the cleaner of the two. - The information about deleting old keys was confusing: - It instructed the user to manually copy & paste the key ids in their script. Manually copy/pasting them is not necessary when the $keys variable can be used to pass the keys into `Remove-MsolServicePrincipalCredential`. - It was further confusing because the line where they're supposed to paste the keys is immediately after the line retrieving the keys, and there was nothing in the script that would output them to the console so they could copy/paste them. These changes should hopefully make this document a bit clearer.
1 parent 40d5978 commit 43e3da3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (Get-Date) -EndDate $dtEnd
70+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate $dtEnd
71+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -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)