Stateless Silhouette Cookie Authenticator 无法找到/删除 cookie

Stateless Silhouette CookieAuthenticator can't find / deletes cookie

我有一个 Play 应用程序,它允许用户通过社交提供商登录,并且身份验证设置与 Play-Silhouette-Slick 种子示例相同。下面的代码可能没问题,但我还是包含了它。

def authenticate(provider: String): Action[AnyContent] = Action.async { implicit request =>
(socialProviderRegistry.get[SocialProvider](provider) match {
  case Some(provider: SocialProvider with CommonSocialProfileBuilder) =>
    provider.authenticate().flatMap {
      case Left(result) => Future.successful(result) // Redirect user to social provider
      case Right(authInfo) => for {
        profile <- provider.retrieveProfile(authInfo)
        user <- userService.save(profile)
        authInfo <- authInfoRepository.save(profile.loginInfo, authInfo)
        authenticator <- silhouette.env.authenticatorService.create(profile.loginInfo)
        cookie <- silhouette.env.authenticatorService.init(authenticator)
        result <- silhouette.env.authenticatorService.embed(cookie, Redirect(routes.EateriesController.eaterySelection()))
      } yield {
        silhouette.env.eventBus.publish(LoginEvent(user, request))
        println("Just to verify that everything went well")
        result
      }
    }
  case _ => Future.failed(new ProviderException(s"Cannot authenticate with unexpected social provider $provider"))
}).recover {
  case e: ProviderException =>
    logger.error("Unexpected provider error", e)
    Redirect(routes.SignInController.index()).flashing("error" -> Messages("could.not.authenticate"))
  }
}

我的问题是,在用户登录后,我的应用程序的端点无法检测到用户已登录。当我在登录后立即被重定向到该页面时,我可以在 Firefox 中验证身份验证器 cookie 是已设置,但只要我导航到应用程序中的另一个页面,cookie 就不再存在。

我猜我的应用程序认为 cookie 无效或什么的,然后将其删除,但我目前没有任何线索。发生这种情况是否还有其他原因/我应该如何记录我的应用程序以缩小问题范围?

我建议您的 cookie 已过期。

您可以在 CookieAuthenticatorSettings 中进行配置,将 cookieMaxAge 设置为 None,这意味着生成的 cookie 是暂时的。

我的依赖注入设置错误。我没有删除将本地时区时钟绑定为时钟实例的行,我想这会导致剪影模块使用不正确的时钟。我现在有这条线:

bind[Clock].toInstance(Clock())

并删除了这一行:

bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)