Single Sign On (SSO) is a feature thats built into Discourse. In fact, we’re using it on this very forum with the Upcase app, and you have access to that code.
Once your app has this functionality in it (the Upcase app also has specs for the functionality, be sure to look at them) then there are settings in the Discourse admin that you can enable to enable SSO against your Rails app.
Let me know if you have any more questions or issues with any of this. Good luck!