gpt4 book ai didi

scala - 如何使用 Play Silhouette 实现无状态 cookie 身份验证?

转载 作者:行者123 更新时间:2023-12-04 19:46:22 24 4
gpt4 key购买 nike

下面的链接说您可以将 CookieAuthenticator 用作无状态或有状态。

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

但是我在下面的链接中看不到任何选项可供选择。

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

我已经复制了以下示例的实现。这是无状态的还是有状态的?如果它是有状态的,我该如何实现无状态身份验证?

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

最佳答案

都是对的。

查看CookieAuthenticator.scala 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]

所以你只需要创建 CookieAuthenticatorService定义了存储库。

在您的示例中,您可以找到一个字符串
new CookieAuthenticatorService(config, None, fingerprintGenerator, idGenerator, clock)
repository这里的参数是 None所以 CookieAuthenticator是无国籍的。

关于scala - 如何使用 Play Silhouette 实现无状态 cookie 身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35986746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com