ceran ceran - 3 months ago 25
Scala Question

play-silhouette: specify body parser for (Un)SecuredAction?

I'm using silhouette for authentication in a play web application and want to do something like this:

def action = UnsecuredAction(BodyParsers.parse.json).async { implicit request =>
// use json
}


This seems to be possible when using Play's build-in
Action
, but not with silhouette's
UnsecuredAction
and
SecuredAction
. Is there a way to do this without having to fall back to silhouette's
(Un)SecuredRequestHandler
or having to check manually if the body is actually JSON?

Answer

You can parse your request body to JSON by using async(parse.json).

For example:

def index = silhouette.SecuredAction.async(parse.json) { implicit request =>
   // Write your code here...
}
Comments