I think you can have a look for the tutorial I have written.
I use this function to connect my NextCloud to my Discourse.