ALM API install provider-host app from tenant app catalog site failed via AAD app-only token
I use AAD App to get SharePoint app-only token, and then install Provider Hosted app from tenant app catalog, the app status always be installing.
This is install error in app monitor detail page:
Version | 2.0.0.1 Installed by | SharePoint App Installed date | Tuesday, March 20, 2018
Type | Component | Error | Correlation ID Intermittent(Retry operation) | Common App Deployment | The operation took too long. | 46e0213b-fc62-43ce-a2e6-7216fa8706c1
It is very strange: The app shown in site contents is gray, and cannot be clicked. But on left quick launch of classic experience, I can click it, and redirect to app URL successfully. And the app parts in the app can be shown when inserting app part into page.

@VesaJuvonen
Any update? Thanks!
I have the same issue. Also same issue when installing provider hosted app from Site Collection App Catalog.
Eventually you'll get the option to click Retry. If retry is clecked, the app is installed right away.
I'm also still having issues using ALM to install a provider hosted app. Using an AAD application identity it fails but the exact same code using a user account contexts works fine. This is all via the tenant app catalog.
No errors are returned from PnP ALM itself, but in the SharePoint UI the app starts installing and seems to get stuck and eventually time out. Error reported in SharePoint is "The operation took too long". Presumably something to do with the apps permission request.
The app itself is requesting Manage rights to the sitecollection. Have also tried scoping this to the tenant and installing the app manually in another site in the hope it might give it rights across the tenant but doesn't seem to help.
I'm using SharePointPnPCoreOnline v2.25.1804.1
@VesaJuvonen any update for this issue? Thanks!
I was wondering if anyone had found a solution to this issue. I have a complex provisioning process that requires several custom apps to be installed on the site collection - completely unattended. It is operating under an AAD application identity. If I monitor the installation status for the add-in it goes from installing --> initializing and then hags. Eventually the UI display a failure message - clicking retry immediately corrects the issue (but requires human interaction which is not a solution).
Is there a way to mimic the retry functions being called in the UI, or has the root issue been corrected?
I am executing SharePointPnPCoreOnline 2.28.1807.
@jcharikofsky if you have username and password, you can call SharePoint CSOM to set this user as site admin first, and then use ADAL to get SharePoint access token of this user to call ALM API to install APP. If you don't have, there is no way right now.
@VesaJuvonen @andrewconnell Any news on this? We (as an ISV) are also running into this issue, with SPFx app it works fine but Provider Hosted apps are failing when not having a user context. Our customers have the 'legacy auth context' disabled so we don't have any other options left than running our provisioning scripts with the app-only token. We don't want to redesign all of our provider hosted apps just because somewhere in a back-end job/process the lack of a user context in the token is throwing an error.
As discussed above, the app runs totally fine while installing is in progress, it is just rolled back after a long period of time and set to a 'failed' mode which then disables the app.
At least there should be decent documentation around this, while this scenario is still a valid one in our opinion.
Looking back at Vesa's question in the comment that triggered you to open this issue, one thing hasn't been answered in this or any of the other referenced issues:
How did you get app-only token? - appregnew or AAD?
I'll add, what specific error response do you get back when you use the REST API (not PowerShell / Office 365 CLI)?
I can't speak for @AveAdam (who opened this issue originally) but we get the token via AAD app registration. To overcome an issue with registering Event Receivers we already registered the app in the appregnew page, but that has no effect on our findings with installing provider hosted apps (via PowerShell, CLI, Site script etc.).
Also there's no error response back because it's an async process of installing the app.
We already have a ticket with MS support (15614891) but there's not much response in the last month other than that it has something todo with missing a user context in the token and that 'legacy' app deployment process (not PFX) was not designed to work with app-credentials. This gives us the feeling that this ticket will end up as 'by design'. This frightens us in a way that there will be more and more customers where we can't have our provider hosted apps installed in an automated way while, for example CSP's, are 'forced' to disable legacy auth context.
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within next 7 days of this comment. Thank you for your contributions to SharePoint Developer activities.
Closing issue due no response from original author. If this issue is still occurring, please open a new issue with additional details. Notice that if you have included another related issue as additional comment on this, please open that also as separate issue, so that we can track it independently.