The easiest approach is to use the Discourse WordPress plugin: WP Discourse – WordPress plugin | WordPress.org and enable Single Sign On between WordPress and your forum. This will make your WordPress site responsible for all user authentication on Discourse.
To automatically add users to groups will require a bit of custom code. The WP Discourse plugin has a couple of functions that can be used when SSO is enabled for automatically adding and removing users from Discourse groups. The functions are add_user_to_discourse_group
and remove_user_from_discourse_group
. You can find them here: wp-discourse/lib/utilities.php at main · discourse/wp-discourse · GitHub.
There is some information about using these functions in this topic: Manage group membership in Discourse with WP Discourse SSO.