If you are referencing JWT when you say token-based, you can take a look at this example of implementing basic HTTP authentication in Play2, and this answer is re: how to implement JWT on the Scala backend. The good part is that you do not need cookies or cache for authenticated users.
Including content from the 1st link for convenience:
def Secured[A](username: String, password: String)(action: Action[A]) = Action(action.parser) { request => request.headers.get("Authorization").flatMap { authorization => authorization.split(" ").drop(1).headOption.filter { encoded => new String(org.apache.commons.codec.binary.Base64.decodeBase64(encoded.getBytes)).split(":").toList match { case u :: p :: Nil if u == username && password == p => true case _ => false } }.map(_ => action(request)) }.getOrElse { Unauthorized.withHeaders("WWW-Authenticate" -> """Basic realm="Secured"""") } }
Use the following:
def myAction = Secured("admin", "1234secret") { Action { request => Ok } }
Costas kotsokalis
source share