How can I check in my website if the user is logged in to my Discourse?

If the user logs in on the forum website, then how can I later get the SSO payload? I know how to get it when I initiate the login myself (by generating a link {forum_url}/session/sso_provider?sso=... etc), but when the user initiates the login, then I have no idea how I could get the SSO payload.

That should indeed be possible, although the exact URL for the API request doesn’t seem to be documented in https://docs.discourse.org. What would be the correct URL?