Skip to content

Commit f76e3f4

Browse files
andrewconnellVesaJuvonen
authored andcommitted
fix indentation issue (SharePoint#3133)
fixes SharePoint#3099
1 parent 655a953 commit f76e3f4

File tree

1 file changed

+70
-75
lines changed

1 file changed

+70
-75
lines changed

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

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,101 +20,98 @@ Ensure the following before you begin:
2020
- [Microsoft Online Services Sign-In Assistant](https://www.microsoft.com/en-us/download/details.aspx?id=39267) is installed on the development computer.
2121

2222
- Microsoft Online Services PowerShell Module ([32-bit](http://go.microsoft.com/fwlink/p/?linkid=236298); [64-bit](http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185)) is installed on the development computer.
23-
23+
2424
- You are 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.
25-
2625

2726
## Find out the expiration dates of the SharePoint Add-ins installed to the Office 365 tenancy
2827

2928
1. Open Windows PowerShell and run the following cmdlet:
30-
29+
3130
```powershell
32-
Connect-MsolService
31+
Connect-MsolService
3332
```
3433

3534
2. 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.
36-
35+
3736
3. 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:
38-
37+
3938
- 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).
40-
39+
4140
- From the remainder, it filters out non-SharePoint add-ins and add-ins that use asymmetric keys, such as workflows.
4241

4342
```powershell
44-
$applist = Get-MsolServicePrincipal -all |Where-Object -FilterScript { ($_.DisplayName -notlike "*Microsoft*") -and ($_.DisplayName -notlike "autohost*") -and ($_.ServicePrincipalNames -notlike "*localhost*") }
45-
46-
foreach ($appentry in $applist) {
47-
$principalId = $appentry.AppPrincipalId
48-
$principalName = $appentry.DisplayName
49-
50-
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | ? { $_.Type -eq "Password" } | % { "$principalName;$principalId;" + $_.KeyId.ToString() +";" + $_.StartDate.ToString() + ";" + $_.EndDate.ToString() } | out-file -FilePath c:\temp\appsec.txt -append
51-
}
43+
$applist = Get-MsolServicePrincipal -all |Where-Object -FilterScript { ($_.DisplayName -notlike "*Microsoft*") -and ($_.DisplayName -notlike "autohost*") -and ($_.ServicePrincipalNames -notlike "*localhost*") }
44+
45+
foreach ($appentry in $applist) {
46+
$principalId = $appentry.AppPrincipalId
47+
$principalName = $appentry.DisplayName
48+
49+
Get-MsolServicePrincipalCredential -AppPrincipalId $principalId -ReturnKeyValues $false | ? { $_.Type -eq "Password" } | % { "$principalName;$principalId;" + $_.KeyId.ToString() +";" + $_.StartDate.ToString() + ";" + $_.EndDate.ToString() } | out-file -FilePath c:\temp\appsec.txt -append
50+
}
5251
```
5352

5453
4. Open the file C:\temp\appsec.txt to see the report. Leave the Windows PowerShell window open for the next procedure, if any of the secrets are near expiration.
55-
5654

5755
## Generate a new secret
5856

5957
1. Create a client ID variable with the following line, using the client ID of the SharePoint Add-in as the parameter.
60-
58+
6159
```powershell
62-
$clientId = 'client id of the add-in'
60+
$clientId = 'client id of the add-in'
6361
```
6462

6563
2. Generate a new client secret with the following lines:
66-
64+
6765
```powershell
68-
$bytes = New-Object Byte[] 32
69-
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
70-
$rand.GetBytes($bytes)
71-
$rand.Dispose()
72-
$newClientSecret = [System.Convert]::ToBase64String($bytes)
73-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
74-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
75-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
76-
$newClientSecret
66+
$bytes = New-Object Byte[] 32
67+
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
68+
$rand.GetBytes($bytes)
69+
$rand.Dispose()
70+
$newClientSecret = [System.Convert]::ToBase64String($bytes)
71+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
72+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
73+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate (Get-Date) -EndDate (Get-Date).AddYears(1)
74+
$newClientSecret
7775
```
7876

7977
3. The new client secret appears on the Windows PowerShell console. Copy it to a text file. You use it in the next procedure.
8078

8179
> [!TIP]
8280
> By default, the add-in secret lasts one year. You can set this to a shorter or longer (up to 3 years maximum) by using the **-EndDate** parameter on the three calls of the **New-MsolServicePrincipalCredential** cmdlet. The value of the parameter must be a [DateTime](https://msdn.microsoft.com/EN-US/library/03ybds8y) object set to no longer than 3 years from **DateTime.Now**.
83-
81+
8482
## Update the remote web application in Visual Studio to use the new secret
8583

8684
> [!IMPORTANT]
87-
> If your add-in was originally created with a pre-release version of the Microsoft Office Developer Tools for Visual Studio, it may contain an out-of-date version of the TokenHelper.cs (or .vb) file. If the file does not contain the string "secondaryClientSecret", it is out of date and must be replaced before you can update the web application with a new secret. To obtain a copy of a release version of the file, you need Visual Studio 2012 or later. Create a new SharePoint Add-in project in Visual Studio. Copy the TokenHelper file from it to the web application project of your SharePoint Add-in.
88-
85+
> If your add-in was originally created with a pre-release version of the Microsoft Office Developer Tools for Visual Studio, it may contain an out-of-date version of the TokenHelper.cs (or .vb) file. If the file does not contain the string "secondaryClientSecret", it is out of date and must be replaced before you can update the web application with a new secret. To obtain a copy of a release version of the file, you need Visual Studio 2012 or later. Create a new SharePoint Add-in project in Visual Studio. Copy the TokenHelper file from it to the web application project of your SharePoint Add-in.
86+
8987
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:
90-
91-
```XML
92-
<appSettings>
93-
<add key="ClientId" value="your client id here" />
94-
<add key="ClientSecret" value="your old secret here" />
95-
... other settings may be here ...
96-
</appSettings>
9788

89+
```XML
90+
<appSettings>
91+
<add key="ClientId" value="your client id here" />
92+
<add key="ClientSecret" value="your old secret here" />
93+
... other settings may be here ...
94+
</appSettings>
9895
```
9996

10097
2. Change the name of the **ClientSecret** key to `SecondaryClientSecret` as shown in the following example:
101-
98+
10299
```XML
103-
<add key="SecondaryClientSecret" value="your old secret here" />
100+
<add key="SecondaryClientSecret" value="your old secret here" />
104101
```
105102

106103
> [!NOTE]
107104
> If you are performing this procedure for the first time, there is no **SecondaryClientSecret** property entry at this point in the configuration file. However, if you are performing the procedure for a subsequent client secret expiration (second or third), the property **SecondaryClientSecret** is already present and contains the initial or already expired old secret. In this case, delete the **SecondaryClientSecret** property first before renaming **ClientSecret**.
108105
109106
3. Add a new **ClientSecret** key and give it your new client secret. Your markup should now look like the following:
110-
107+
111108
```XML
112-
<appSettings>
113-
<add key="ClientId" value="your client id here" />
114-
<add key="ClientSecret" value="your new secret here" />
115-
<add key="SecondaryClientSecret" value="your old secret here" />
116-
... other settings may be here ...
117-
</appSettings>
109+
<appSettings>
110+
<add key="ClientId" value="your client id here" />
111+
<add key="ClientSecret" value="your new secret here" />
112+
<add key="SecondaryClientSecret" value="your old secret here" />
113+
... other settings may be here ...
114+
</appSettings>
118115
```
119116

120117
> [!IMPORTANT]
@@ -129,47 +126,45 @@ foreach ($appentry in $applist) {
129126
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.
130127

131128
1. Connect to MSOnline using the tenant admin user with the following markup using SharePoint Windows PowerShell.
132-
129+
133130
```powershell
134-
import-module MSOnline
135-
$msolcred = get-credential
136-
connect-msolservice -credential $msolcred
131+
import-module MSOnline
132+
$msolcred = get-credential
133+
connect-msolservice -credential $msolcred
137134
```
138135

139136
2. 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 appers there.
140-
141-
> [!NOTE]
137+
138+
> [!NOTE]
142139
> The **clientId** needs to match your expired **clientId**. It's recommended to delete all keys, both expired and unexpired, for this **clientId**.
143-
140+
144141
```powershell
145-
$clientId = "27c5b286-62a6-45c7-beda-abbaea6eecf2"
146-
$keys = Get-MsolServicePrincipalCredential -AppPrincipalId $clientId
147-
Remove-MsolServicePrincipalCredential -KeyIds @("KeyId1"," KeyId2"," KeyId3") -AppPrincipalId $clientId
142+
$clientId = "27c5b286-62a6-45c7-beda-abbaea6eecf2"
143+
$keys = Get-MsolServicePrincipalCredential -AppPrincipalId $clientId
144+
Remove-MsolServicePrincipalCredential -KeyIds @("KeyId1"," KeyId2"," KeyId3") -AppPrincipalId $clientId
148145
```
149146

150147
3. Generate a new **ClientSecret** for this **clientID**. It uses the same **clientId** as set in the preceding step. The new **ClientSecret** is valid for 3 years.
151-
148+
152149
```powershell
153-
$bytes = New-Object Byte[] 32
154-
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
155-
$rand.GetBytes($bytes)
156-
$rand.Dispose()
157-
$newClientSecret = [System.Convert]::ToBase64String($bytes)
158-
$dtStart = [System.DateTime]::Now
159-
$dtEnd = $dtStart.AddYears(3)
160-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
161-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
162-
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
163-
$newClientSecret
150+
$bytes = New-Object Byte[] 32
151+
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
152+
$rand.GetBytes($bytes)
153+
$rand.Dispose()
154+
$newClientSecret = [System.Convert]::ToBase64String($bytes)
155+
$dtStart = [System.DateTime]::Now
156+
$dtEnd = $dtStart.AddYears(3)
157+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Sign -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
158+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Symmetric -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
159+
New-MsolServicePrincipalCredential -AppPrincipalId $clientId -Type Password -Usage Verify -Value $newClientSecret -StartDate $dtStart -EndDate $dtEnd
160+
$newClientSecret
164161
```
165162

166-
4. Copy the output of **$newClientSecret**.
167-
168-
5. Replace the **Web.config** with this **ClientId** and **ClientSecret**. You don't need **SecondaryClientSecret** app settings.
169-
163+
4. Copy the output of **$newClientSecret**.
164+
165+
5. Replace the **Web.config** with this **ClientId** and **ClientSecret**. You don't need **SecondaryClientSecret** app settings.
166+
170167
6. Wait at least 24 hours to propagate **ClientSecret** to SharePoint Office (SPO).
171-
172-
173168

174169
## See also
175170

0 commit comments

Comments
 (0)