I am using Scala & Play 2.0
I have a URL as such:
/v1/people/search/MTIyOjg3YjYzNmU1YTk5MDdkYjY2MzAyODZiM2RkNTMzYzYw
In my routs file:
POST /v1/people/search/:authToken controllers.v1.Application.searchPeople(authToken: String)
What I am trying to do is create a secure trait and take the :aythToken and validate via a custom Action that replaces it in my function/method call:
Make Action a CustomAuthAction
def searchPeople(authToken: String) = Action { implicit request => }
So that I can reject a request based on the already parsed :authToken without setting this value as a cookie, I already know how to that.
So how can I take the already passed by play :authToken and pass it to a custom action?
Thanks
Here is my solution:
case class CheckSessionRequest(val user: User, request: Request[AnyContent]) extends WrappedRequest(request)
def RequireAuthToken(f: CheckSessionRequest => Result): Action[AnyContent] = {
Action { request =>
UserValidation.findUserByAuthToken(StringUtil.getAuthTokenFromURL(request.toString)).map { user =>
f(CheckSessionRequest(user, request))
}.getOrElse( // STRANGE ERROR
Ok(Json.generate(StatusHandler("failed","Unknown Login Error","{}"))).withHeaders(
CONTENT_TYPE -> "application/json"
)
)
}
}