Search code examples
playframeworksecuresocial

Querying SecureSocial for currently signed-in users


Is there a way to know which users are currently signed in with a Playframework application using the Secure Social API? If so how?

More generally where and how are currently signed-in users stored in a Play/SecureSocial application?


Solution

  • SecureSocial keeps track of authenticated users using the the AuthenticatorStore plugin. The default implementation uses the Play cache but you can create your own. If you create your own implementation then you can decide where to save the session and then query that to find out what you need.

    Another approach could be to write an EventListener. SecureSocial fires Login and Logout events. You can persist those events and that would also give you the active users. You can however loose logout events in this case if the user just closes the browser. I'd say relying in the AuthenticatorStore is more reliable because Authenticators have an expiration that you can check when running a query.