|
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: 1/18/2020 |
| 4 | +ms.date: 11/10/2020 |
5 | 5 | ms.prod: sharepoint
|
6 | 6 | localization_priority: Priority
|
7 | 7 | ---
|
@@ -64,9 +64,11 @@ Ensure the following before you begin:
|
64 | 64 | $rand.GetBytes($bytes)
|
65 | 65 | $rand.Dispose()
|
66 | 66 | $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 |
70 | 72 | $newClientSecret
|
71 | 73 | ```
|
72 | 74 |
|
@@ -128,15 +130,21 @@ For expired client secrets, first you must delete all of the expired secrets for
|
128 | 130 | connect-msolservice -credential $msolcred
|
129 | 131 | ```
|
130 | 132 |
|
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. |
132 | 134 |
|
133 | 135 | > [!NOTE]
|
134 | 136 | > The **clientId** needs to match your expired **clientId**. It's recommended to delete all keys, both expired and unexpired, for this **clientId**.
|
135 | 137 |
|
136 | 138 | ```powershell
|
137 | 139 | $clientId = "27c5b286-62a6-45c7-beda-abbaea6eecf2"
|
138 | 140 | $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 |
140 | 148 | ```
|
141 | 149 |
|
142 | 150 | 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