【问题标题】:Session Authentication not working in Play when using Silhouette使用 Silhouette 时会话身份验证在 Play 中不起作用
【发布时间】:2018-10-23 04:30:16
【问题描述】:

我正在使用Silhouette 安全库。我的Play 服务器似乎发送空的Session 信息作为响应。我做错了什么?

以下是发送响应之前在Play's 控制台上的打印。

Session(Map(authenticator -> 1-jtwBvA+LsLKE2rnkT/nMH1aQF9xc1twhECrma9mj3NUhUdVDmh/4wxQ2MxDOjcxkvEMTi1k63Dg5ezl+9FzDE3miaM5DbOrhyqAyGu4+30mHHV3QdPKA3IQQx5UdL1Hu85fZRI4f3Ef+q6xAgboDps0uBob5ojzo5Oqy8FNsoexn7Wr9iRyTr5xrMrLvl9GNQa+rA3q8qvW84sJaSei2iydrP2OjUbnnzo+zgrHLB3Bn7KJxOcFH4h9CikZNk/FHbtDm4uxzcK3paK1CuuIWLE8yvcYdavJ+4ejV5IaJ8QesJQRFgBktD9L/A2bc03eaA8wm)))

但在浏览器窗口中,我注意到该值为空。

Set-Cookie: PLAY_SESSION=; Max-Age=-86400;

请注意,我的浏览器之前已经有一个来自之前测试运行的 PLAY_SESSION cookie。但是,我希望客户端应用程序(Angular)会用新的 cookie 覆盖旧的 cookie。我说的对吗?

以下是创建、初始化和嵌入会话信息的代码 sn-p

val AuthenticatorFuture: Future[SessionAuthenticator] = silhouette.env.authenticatorService.create(loginInfo) //create authenticator

                      AuthenticatorFuture.flatMap(authenticator => { //got the authenticator
                        val securityTokenFuture: Future[Session] = silhouette.env.authenticatorService.init(authenticator) //init authenticator
                        securityTokenFuture.flatMap(securityToken=> { 
                          println("adding security token: ",securityToken)
                          val result:Future[AuthenticatorResult] = silhouette.env.authenticatorService.embed(securityToken, Ok(Json.toJson(JsonResultSuccess("found user"))))
                          result

Environment 定义为

trait SessionEnv extends Env {
  type I = User 
  type A = SessionAuthenticator
}

作为传递给我的控制器

silhouette: Silhouette[SessionEnv]

我在编译时创建的如下

val configSession =  SessionAuthenticatorSettings()
val sessionAuthenticatorService = new SessionAuthenticatorService(configSession,fingerprintGenerator,authenticatorEncoder,new DefaultSessionCookieBaker(),clock)
val sessionEnv = com.mohiva.play.silhouette.api.Environment[SessionEnv](userIdentityService,sessionAuthenticatorService,Seq(),EventBus())

【问题讨论】:

    标签: playframework-2.6 silhouette


    【解决方案1】:

    问题可能是Play Framework 的预期行为,因为Silhouette 不会修改会话cookie。我注意到浏览器已经有一个以前过期的 cookie,它在signin 请求中发送它。当Silhouette 验证器看到过期的cookie 时,它​​会返回一个空值。我想这是为了让浏览器丢弃之前的cookie。

    【讨论】:

      猜你喜欢
      • 2016-12-14
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 2016-06-29
      • 2014-05-09
      • 1970-01-01
      相关资源
      最近更新 更多