2016-03-14 1 views
5

Le lien ci-dessous indique que vous pouvez utiliser CookieAuthenticator sans état ou avec état.Comment implémenter l'authentification par cookie sans état à l'aide de Play Silhouette?

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

Mais je ne vois aucune option pour faire le choix sur le lien ci-dessous.

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

J'ai copié la mise en œuvre de l'exemple ci-dessous. Est-ce apatride ou dynamique? Si son stateful comment puis-je implémenter l'authentification sans état?

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

Répondre

4

Il est tout correct.

regarder dans la source CookieAuthenticator.scala sur la 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] 

Alors il vous suffit de créer CookieAuthenticatorService avec le référentiel défini.

Dans votre exemple, vous pouvez trouver une chaîne

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

Le paramètre repository est None ici si CookieAuthenticator est apatride.