Replies: 1 comment 1 reply
-
@phelps-sg what if the request has JSON content type? How about using it as a I have interesting in developing this solution if the community accepts it as a viable feature implementation. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have also asked this question on StackOverflow (https://stackoverflow.com/questions/73926931/in-scala-play-framework-is-there-a-simple-way-to-verify-signatures-on-form-requ), but also posting here because there has not yet been a response.
I am trying to write a Scala Play Framework action that will verify a HmacSHA256 signature on an incoming POST request containing form-url-encoded data.
This does not seem straightforward in the Play framework because: i) actions builders only have access to headers, but do not have access to the request body, and ii) in order to calculate the signature we have to treat the request body as
Array[ByteString]
, but when we come to process the form data we have to treat it asMap[String, Seq[String]]
, the problem being that Play forces us to choose a single type for our request, and we cannot easily "cast" the request body to a different type.The only solution I have been able to come up with is to use an
ActionRefiner
that returns aWrappedRequest
that embeds a callback to validate the signature. The callback in turn reparses the data usingFormUrlEncodedParser.parse(new String(request.body.toArray))
. This approach is illustrated in the code below.This all seems overly convoluted. Is there a simpler way to verify Hmac signatures in Play, or am I simply running up against limitations of the API?
The validation on the controller side looks like this:
Beta Was this translation helpful? Give feedback.
All reactions