How to implement stateless cookie authentication using Play Silhouette?

The link below says that you can use CookieAuthenticator as a stateless person or condition.

http://silhouette.mohiva.com/docs/authenticator

But I do not see any options at the link below.

http://silhouette.mohiva.com/v3.0/docs/config-authenticators#cookieauthenticator

I copied the implementation for the example below. Is it stateless or stateless? If its state, how can I implement authentication without saving state?

https://github.com/mohiva/play-silhouette-seed

+5
source share
1 answer

All is correct.

take a look at the CookieAuthenticator.scala source on github: https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/impl/authenticators/CookieAuthenticator.scala

 /** * The service that handles the cookie authenticator. * * @param settings The cookie settings. * @param repository The repository to persist the authenticator. Set it to None to use a stateless approach. * @param fingerprintGenerator The fingerprint generator implementation. * @param idGenerator The ID generator used to create the authenticator ID. * @param clock The clock implementation. * @param executionContext The execution context to handle the asynchronous operations. */ class CookieAuthenticatorService( settings: CookieAuthenticatorSettings, repository: Option[AuthenticatorRepository[CookieAuthenticator]], fingerprintGenerator: FingerprintGenerator, idGenerator: IDGenerator, clock: Clock)(implicit val executionContext: ExecutionContext) extends AuthenticatorService[CookieAuthenticator] 

So you just need to create a CookieAuthenticatorService with a specific repository.

In your example you can find the line

 new CookieAuthenticatorService(config, None, fingerprintGenerator, idGenerator, clock) 

The repository parameter is None here, so CookieAuthenticator is stateless.

+4
source

Source: https://habr.com/ru/post/1245006/


All Articles