Last week it was my lucky day: one of my 5 year old projects emerged and needed an update. The client was rationalizing their Azure resources, putting naming conventions in place etc. and our provider-hosted app needed to be changed to follow them.
In essence, we needed to do the following steps:
- Deploy the code to a new Azure App Service, in the correct subscription with naming conventions for the URL.
- Adjust the App Registration in SharePoint to reflect the new Redirect Uri and App Domain
- Deploy an updated app package with an increased version number and using the new URL.
I remembered doing this before, so thought it was going to be easy. Steps 1 and 3 were piece of cake, but step 2 gave me troubles. The official documentation around updating an app doesn't cover this part, it only talks about the code or updating an expired client secret.
My memory and Googling gave me the following solution: go to <<url>>/_layouts/15/appinv.aspx
, enter the existing Client Id, press lookup, adjust the values and click "Create". It didn't work...
I refused to believe that the only way to achieve my goal was to delete the app registration (service principal), and then re-register it with the same client id.
It turns out (after validating with some contacts), I had to believe it so I'm writing this down to never forget.
Delete the Service Principal
I used the new Azure Powershell cmdlets to remove the existing service principal by id. The commands are rather simple:
Connect-AzAccount -Tenant <<your tenant id>>
Remove-AzADServicePrincipal -ApplicationId <<your application id>>
Disconnect-AzAccount
Redo the App Registration
With the "old" service principal removed, I could redo the registration using appregnew.aspx. The documentation is clear:
- Go to
/_layouts/15/AppRegNew.aspx
by using a web browser. - Enter the correct information (App Domain, Redirect URI), generate a new Client Secret and make sure to put the existing Client Id in the form.
- Click "Create".
Now I could adjust the app package with the new information, and upload it into the App Catalog.