I haven’t done this myself before, but this piqued my interest when I read the topic. I was able to find this, which seems to have the information you are interested in:
If you read through the post, Haso appears to be doing something similar to what you are interested in. If you want security to be upheld based on that users permissions, you should be good to go. It was a good read, definitely saving it for later myself.