2017-04-01 8 views
0

私はユーザーにソーシャルプロバイダにログインし、Play-Silhouette-Slickシードの例と同じように認証を設定できるようにするPlayアプリを持っています。次のコードは大丈夫ですが、とにかくそれを含めました。ステートレスシルエットCookieAuthenticatorはクッキーを見つけられない/削除できません

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で確認できますクッキーは設定されていますが、アプリで別のページに移動するとすぐにクッキーは存在しなくなります。

私のアプリは、クッキーが無効であると思っていたり、それを削除していると思っていますが、現在は手がかりがありません。これが起こる可能性がある他の理由がいくつかありますか、問題を絞り込むためにアプリケーションを記録する方法はありますか?

答えて

1

あなたのクッキーが期限切れになったことをお伝えします。

cookieAuthenticatorSettingsでこれを設定できます。これはcookieMaxAgeがNoneに設定されているため、結果のCookieが一時的です。

+0

を私は今、このラインを持っています。 : – rusins

+0

クッキーパスはどうですか? – mavarazy

+0

クッキーパスは「/」に設定されています。 – rusins

0

私の依存性注入が間違っていました。私は時計のインスタンスとしてローカルタイムゾーンクロックをバインドする行を削除していない、私はシルエットモジュールが間違ったクロックを使用する原因と推測する。

bind[Clock].toInstance(Clock()) 

と、この行削除:残念ながら、それはそれではなかった

bind(classOf[Clock]).toInstance(Clock.systemDefaultZone) 
関連する問題