Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to original body when using wrap-json-params middleware #47

Open
erez-rabih opened this issue Sep 4, 2016 · 4 comments
Open

Comments

@erez-rabih
Copy link

Currently there is no way to access the original body of the request when using the middleware since the middleware reads and InputStream and there's no way to reset its position to 0.

I'd suggest at least assoc-ing the body string from here: https://github.com/ring-clojure/ring-json/blob/master/src/ring/middleware/json.clj#L14 to the request map for future reference.

@weavejester
Copy link
Member

What's the use-case?

@erez-rabih
Copy link
Author

The use case is verifying webhook authenticity from Shopify: https://help.shopify.com/api/tutorials/webhooks#verify-webhook

I need to compare a given signature with a signature I make on the request body to make sure this is an authentic call from Shopify.

If I use the middleware I can't read the body myself to compare the signatures. I had to create a custom middleware to duplicate the body as two InputStream objects but that looks like a patch.

I believe developers should always have access to the original request as it was sent regardless of which middleware they chose to use.

This issue is related to #43 #31

@weavejester
Copy link
Member

Rather than create a solution specifically for Ring-JSON, it might be better to create some middleware that reads the body InputStream, and then replaces it with a ByteArrayInputStream. The stream could also be added to an additional key for middleware that happen to replace the request body.

@ska2342
Copy link

ska2342 commented Mar 11, 2017

GitHub seems to be doing exactly what shopify does. So, here is a gist outlining the solution I created after the short discussion in #43

https://gist.github.com/ska2342/4567b02531ff611db6a1208ebd4316e6

IMHO, that is perfectly fine the way it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants