Group setting to nextcloud

I am doing this very customized setup with nextcloud and discourse. I’d like to study the possibility to connect discourse group (so all members of the group would have access). Is this possible? How hard is to make a setting for each group?

Technically:
I want that a user can login to a nextcloud account using a login defined in a group of discourse. which means, when a user clicks on “Login using discourse” on nextcloud, it should jump to a discourse login page, and if the user is logged in, it shows the groups which are possible to login with nextcloud, and browse nextcloud)

I am also looking for a solution to understand all this settings from discourse
Use nextcloud social