-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add an oAuth HMAC authentication #71
base: master
Are you sure you want to change the base?
Conversation
639e71e
to
c95e4b8
Compare
…asier to make a pipeline and make sure the requests are authenticated.
As always, thank you for contributing 👍 Could you move the HMAC auth into its own module? There is a problem with authenticating hmac in plug based applications, because some plugs (json parse for example) consume the original request body, and the params map is not in the same order as the original params, so the hmac comes out different. This is no problem with query params, but validating webhooks can be tricky to say the least. You can try sorting the params, but iirc if you receive a list, or nested params, it is almost impossible to sort them back into the original format. This is fine for a first draft, but if you want to address the issue I just mentioned, feel free to take some time. If not, let me know and I will take a closer look at the rest 😄 |
Yes I actually ran into a problem while using this with parameters coming in for order ids. So I'll smooth that out :) Where did you have in mind to put the HMAC auth validation? I thought it actually fits in the oAuth module because it's only for oAuth, they have a different authentication scheme for Webhooks. |
👍
Maybe something like HMACAuth.check(params, :oauth)
# and
HMACAuth.check(params, :webhook) |
Ok cool, I'll work out some module for the auth ;) As for the ids parameter, I found that it's a specific issue with bulk menu items, and there is a suggested solution though I haven't managed to make it work validate ... It seems Shopify is quite vague about this scenario: https://community.shopify.com/c/Shopify-APIs-SDKs/HMAC-calculation-vs-ids-arrays/m-p/261154 |
I fixed the issue with the ids parameter in 1ed38f8 It's crazy Shopify don't URI encode it 😮 |
I would maybe try and keep the PR focused on a simple hmac authentication method. One that could be applied against both oauth and webhooks. Something akin to One thing to be aware of is that we need to prevent timing attacks. I've typically done this with Typically I've been using the ueberauth_shopify library for performing oauth. Ueberuath has become the elixir standard for oauth. Couple thoughts:
|
I don't know if it's a good idea to add a dependency for ueberauth_shopify just to make the authentication. Unless I'm missing something why it's good to use that instead of the code already in the lib I'd be happy to understand the benefits :) As for HMAC, it's for authenticating all Shopify requests and not just the preliminary auth one so I think it's better to implement it in the library. Again, please enlighten me if I missed something ;) I'll try to implement the module |
This adds the ability to authenticate the request from Shopify using the HMAC param. I also modified the readme to reflect this change.