Just adding this here in case someone is in need of yet another example of how to do this in ruby:
https://meta.discourse.org/t/official-single-sign-on-for-discourse-sso/13045/372?u=blake
https://github.com/oblakeerickson/sso_endpoint
https://github.com/oblakeerickson/sso_endpoint/blob/master/README.md