Single Sign-Out with Single Page Applications #2884
-
Hey there, I'm currently evaluating how to build a central identity platform for my organizations ecosystem transition. The context I am working with is as follows: We are building everything as SPAs and APIs. APIs are pretty easy to deal with once we have an OIDC/OAuth2 Token, as we can just perform introspection on the API gateways. However, the user-experience on the client-end doesn't seem that great. We checked out kratos to see if it was possible without hydra at all, but that doesn't seem possible at the moment, as we are bound to different domains (See ory/kratos#662 for the state on that end). As of the time of writing this, we have found two ways to achieve this goal reliably enough. Using WebSockets and a PKCE flow.The idea here would be to have the SPA hold the tokens in memory. On start-up the SPA would check if it has a valid token and if not, perform a typical PKCE-based OIDC flow to obtain a new, valid token. The OP would use WebSockets (or something like pusher or ably) to notify a currently open and running application of a state-change for a particular session. The SPA would react to the notification and act accordingly. However, this only works if the SPA is currently open and running in a tab. However if the tab is closed at the time of notification, the check on start-up would make this a non-issue. The advantage would be a simple implementation which is easily achieved with a little bit of code. The downside is of course the storing of tokens in application memory, opening it up to XSS attacks. Using a BFF with WebSocketsThe second approach would be a little more involved but also more secure. Maybe we've overlooked something here, but as far as we can tell, those two options are the only two ways to make it possible for a SPA to be notified of an invalidated session. I'm super stoked to see what other options there might be! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Wouldn’t it be also acceptable for the user to sign in on both domains individually? So the user is not insta logged in everywhere but needs to sign in on both foo.com and bar.com? Logout would still work across domains because we invalidate the session in the DB. It could be a workaround until we have multi domain support available. And maybe it might make more sense to invest the time in the Ory Kratos feature versus a complex web socket set up :) |
Beta Was this translation helpful? Give feedback.
Wouldn’t it be also acceptable for the user to sign in on both domains individually? So the user is not insta logged in everywhere but needs to sign in on both foo.com and bar.com?
Logout would still work across domains because we invalidate the session in the DB.
It could be a workaround until we have multi domain support available. And maybe it might make more sense to invest the time in the Ory Kratos feature versus a complex web socket set up :)