我正在尝试使用其他一些操作来构建基本身份验证:
def findByNameSecure(username: String) = Authenticated { _ =>
val cursor: Cursor[JsObject] = persons.
find(Json.obj("userdetails.username" -> username)).
cursor[JsObject](ReadPreference.primary)
val res = cursor.collect[List]().map { persons =>
Ok(Json.toJson(persons))
} .recover {
case _ => BadRequest(Json.parse("{'error': 'failed to read from db'}"))
}
Await.result(res, 10.seconds)
}
路线:
GET /secure/user/findbyname controllers.UserController.findByNameSecure(username: String)
这可以按预期工作。令人不安的是,我使用了阻塞的Await.result
。如何组成这种身份验证的异步版本?
我正在使用游戏2.4。
答案 0 :(得分:3)
AuthendicatedBuilder
是ActionBuilder
的孩子。所以我认为它的async
方法应该也可以。
使用示例:
def findByNameSecure(username: String) = Authenticated.async { _ =>