File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,10 +79,27 @@ defmodule Shopify.OAuth do
7979
8080 defp valid_hmac? ( secret , params ) do
8181 hmac = params [ "hmac" ]
82- query = params |> Map . delete ( "hmac" ) |> URI . encode_query
8382
84- :crypto . hmac ( :sha256 , secret , query )
83+ :crypto . hmac ( :sha256 , secret , query_string ( params ) )
8584 |> Base . encode16 ( case: :lower )
8685 |> String . equivalent? ( hmac )
8786 end
87+
88+ defp query_string ( params ) do
89+ # Extract the ids and convert them to an array of strings
90+ # ["1", "2", "3"]
91+ ids = params [ "ids" ]
92+ |> Enum . map ( fn x -> "\" #{ x } \" " end )
93+ |> Enum . join ( ", " )
94+
95+ # Remove the ids & hmac parameters and make a query string
96+ query = params
97+ |> Map . delete ( "ids" )
98+ |> Map . delete ( "hmac" )
99+ |> URI . encode_query
100+
101+ # Concatenate the ids back to the query - they must not be URI encoded!
102+ # https://community.shopify.com/c/Shopify-APIs-SDKs/HMAC-calculation-vs-ids-arrays/m-p/261154
103+ "ids=[#{ ids } ]&#{ query } "
104+ end
88105end
You can’t perform that action at this time.
0 commit comments