Search code examples
authenticationplayframework-2.3paasjelastic

Login redirect to login page with play2 auth


I am developping an app and everything was working fine locally. But when I tried to push it to a PaaS (using Jelastic) the authentication module I am using (t2v/play2-auth) does not seem to work anymore. I really have no idea why and would like some explanations. It is my first using PaaS and I think I am not getting everything yet.

For more details: when I try to login, the login seems to work and I am redirected to /home but then for some reason I am redirected automatically to the login page. I suspect because the user is not really authenticated. Why is that?

POST http://app/login [HTTP/1.1 303 See Other 3624ms]
GET  http://app/home  [HTTP/1.1 303 See Other 53ms]
GET  http://app/login [HTTP/1.1 200 OK 107ms]

Thanks to any information or ideas in advance.

EDIT: Here is my AuthConfig trait:

type Id = Long
type User = AccessUser
type Authority = Int
val idTag: ClassTag[Id] = classTag[Id]
val sessionTimeoutInSeconds: Int = 3600

def resolveUser(id: Id)(implicit ctx: ExecutionContext): Future[Option[User]] = Future(AccessProvider.find(id))

def goHome: Future[Result] = Future(Redirect(controllers.users.routes.UserSpaceController.home(0)))

def loginSucceeded(request: RequestHeader)(implicit ctx: ExecutionContext): Future[Result] = {
val uri = request.session.get("access_uri").getOrElse(controllers.users.routes.UserSpaceController.home(0).url.toString)
Future.successful(Redirect(uri).withSession(request.session - "access_uri"))
}

def logoutSucceeded(request: RequestHeader)(implicit ctx: ExecutionContext): Future[Result] =
Future.successful(Redirect(controllers.routes.PublicController.index))

def authenticationFailed(request: RequestHeader)(implicit ctx: ExecutionContext): Future[Result] =
Future.successful(Redirect(controllers.users.routes.SecurityController.login).withSession("access_uri" -> request.uri))

def authorizationFailed(request: RequestHeader)(implicit ctx: ExecutionContext): Future[Result] = 
Future.successful(Forbidden("no permission"))

def authorize(user: User, authority: Authority)(implicit ctx: ExecutionContext): Future[Boolean] = Future.successful {
(user.permission, authority) match {
  some cases
}
}
 override lazy val cookieSecureOption: Boolean = play.api.Play.isProd(play.api.Play.current)

Solution

  • Thanks to @m-z I was able to solve my problem. The solution was indeed the cookieSecureOption=true.

    Indeed the cache might be a problem later on. But for now it is working. Thanks for clarifying.