Background: I have a requirement to make it so that an SFDC connected app defaults/is super easy to set to Admin Users are Pre-authorized
instead of All users may self-authorize
. This setting is important to make this app work and we have historically have had problems with admins not configuring this setting correctly.
Here is a quick history on what I have tried to do to get the isAdminApproved set to "true":
- Directly, via xml definition (doesn't get honored)
- Directly via apex code (doesn't get honored)
- Indirectly via an apex-triggered metadata API call (ended up being more pain than what it was worth and was told that it wouldn't work in prod because of security restrictions)
- Indirectly via a connected-app connected service to make a metadata API call: works in a scratch org but not in prod, which I assume is because it is a managed package. This would occur when an Admin clicks on a button, not from a post-install script.
Details on what I mean by it isn't working in prod:
When I try to do a readMetadata call on my connectedApp objects that are in my managed package, the response comes back as [{\n 'fullName': None\n}]
instead of with the metadata configuration of my connected app.
Here is a sequence diagram of what I am trying to do in #4 right now:
My question is this: Am I on a fool's errand, where this is impossible to do? ...Or is there a way to set a connected app (in a managed package that I publish) to Admin Users are Pre-authorized
without making the admin just do it themselves directly in the settings?
InstallHandler
. On the other hand it might work from a Visualforce button that the admin clicks during setup.readMetadata
onisAdminApproved
within the packaging org itself, but then ran into the same issue in production -readMetadata
doesn't return managed connected apps results, and interestingly enough, workbench also doesn't show managed connected apps (as mentioned in theretreiveConnectedApp()
method in the MetadataServicesExamples file. I don't know if this is a deficiency in Metadata API or notMetadataService
or workbench. It's amazing how such a seemingly insignificant read permission is causing all these issues for ISVs :-/