As far as I know, the same problem has been mentioned two times, and was said to have been fixed in 2018 (Discourse doesn't redirect to return_sso_url after user logs in on private site) and in 2015 (Login redirect during sso provider login). But I am still facing the same issue.
I have installed in our organization a Discourse. We have our own user accounts database, so we use our custom made SSO login website to allow users to login Discourse, using the instructions as in DiscourseConnect - Official Single-Sign-On for Discourse (sso). It works well.
Then, we also have WordPress, Rocket Chat and a custom made Tornado web app. They depend on Discourse as the SSO provider.
For WordPress, we are using wp-discourse. For Rocket Chat and the Tornado web app, we have followed the instructions in Using Discourse as an identity provider (SSO, DiscourseConnect).
The login flow worked well if the user has already logged in to Discourse. However, if the user has not already logged in to Discourse, none of the login flow of the services (e.g. WordPress/Rocket Chat/Tornado web app) worked well. When a user tries to login to WordPress, Rocket Chat or the Tornado web app, they will be redirected to discourse.com/login. Then, the user will click the login button, which will redirect the user to our custom SSO site. There they will perform a login, after which they will be redirected to discourse.com, but not the desired service (e.g. WordPress, Rocket Chat or Tornado web app).
Just a little side track, the wp-discourse Sync Logout with Discourse function does not work. When a user logs out WordPress, they remained logged in to Discourse.
I have been facing this issue for several months after several Discourse updates. Now I am seeking for help. Please let me know if any details are needed.
My current workaround is instead of redirecting the user to /session/sso_provider, redirect them to /session/sso?return_path=customurl. The downside is that it always asks the user to login even if they have already logged in Discourse.