I've noticed that Terminal.app has the ability to request administrator permissions when a program running in it needs them. Is there a public API that would allow other apps to do the same thing?
Requesting full disk access
Yes. Google for "apple authorization services". I would give you a URL, but that would put my reply into quarantine. Also, there are a number of Apple documents on the topic. Some are deprecated. It is a confusing mess and Apple likes it that way because they want to discourage people doing this.
Wait a minute. I took another look at your thread title. What exactly are you asking for? Because even if you have root, you don't get Full Disk Access on Mojave. You have to ask the user for that.
I don't think it's root, but the auth dialog looks similar to the one you mentioned. When you run a program in Terminal.app that needs full disk access (such as crontab -e), it prompts you like this:
Somehow it's getting a signal that a child process is about to get itself in trouble and is able to request escalated priviledges of some kind. Pressing OK allows crontab to succeed.
Curiously, doing "ls ~/Library/Safari" simply fails without a dialog, so there's something more going on than I had initially thought.
Well, that's interesting. If you give it privileges, nothing new shows up in System Preferences. If you deny privileges, they are denied forever. But "tccutil reset All" does work to reset it.
crontab is a bit special. You can run it as a regular user and it will modify system locations. It has setuid root for that, which is a bit unusual.
I would be surprised, nay shocked, if there were any kind of API for this. If you did find out how to use it, Apple would likely consider that a security exploit.
A solution was finally found to this problem, so for posterity's sake, the answer is the NSSystemAdministrationUsageDescription Info.plist key.
The way this was discovered was educational. See the conversation on this pull request for details: