Hi all,
I'm new to Flarum and am exploring how to implement SSO using a domain-wide session cookie. Here’s the setup I am considering:
Main Site (www.example.com): Has a /signin page that sets a domain-wide session cookie (valid for all subdomains of example.com) upon successful login. There's also a /validate endpoint that checks the session cookie and returns 200 OK for valid sessions or 401 Unauthorized for invalid/expired sessions.
Flarum Site (flarum.example.com): Should use the session cookie, already available due to domain-wide scope, to authenticate users. When Flarum frontend calls the backend API the cookie is sent too, so the backend in turn can forward the cookie to the main site’s /validate endpoint to authenticate the session.
I need guidance on integrating this logic with Flarum, please, particularly in scenarios where: If /validate returns 200, the user should be logged into Flarum, and a new user account should be created in the Flarum database if it’s their first login. And I need to redirect users to the main site’s /signin for authentication, and upon returning, the Flarum backend should recognize the set cookie and validate the session. The signout process on Flarum should redirect to the main site’s /signout endpoint, ensuring session termination on both platforms.
From my research on github, I've encountered concepts like Listeners, Controllers, and Middleware in Flarum extensions that implement SSO. Since I don’t require any UI changes (as the login user interface is managed by the main website), my focus is on backend integration for session management.
Could anyone kindly provide insights or examples on how to achieve this? My goal is to manage sessions from a single point, allowing seamless sign-in and sign-out across both the main and Flarum sites.
Thank you for any help or pointers you can provide!