SSO provider feature is inbuilt in Discourse core. So you don’t have to worry about it. Follow this howto Use Discourse as an identity provider (SSO, DiscourseConnect).
In this line you will receive logged-in user details if you configured everything (php code + settings) correctly.