Skip to content

Commit

Permalink
Add temp logging to debug 401 for alliance pro staging
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-voth committed Aug 15, 2024
1 parent 19ec73f commit 034aaf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/shopify_api/plugs/admin_authenticator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ defmodule ShopifyAPI.Plugs.AdminAuthenticator do

defp validate_hmac(%ShopifyAPI.App{client_secret: secret}, params) do
request_hmac = params["hmac"]
Logger.warning("Request hmac is #{request_hmac}")

params
|> Enum.reject(fn {key, _} -> key == "hmac" or key == "signature" end)
|> Enum.sort_by(&elem(&1, 0))
|> Enum.map_join("&", fn {key, value} -> key <> "=" <> value end)
|> ShopifyAPI.Security.base16_sha256_hmac(secret)
|> then(fn
hmac =
params
|> Enum.reject(fn {key, _} -> key == "hmac" or key == "signature" end)
|> Enum.sort_by(&elem(&1, 0))
|> Enum.map_join("&", fn {key, value} -> key <> "=" <> value end)
|> ShopifyAPI.Security.base16_sha256_hmac(secret)

Logger.warning("Hmac after checking against secret is #{hmac}")

then(hmac, fn
^request_hmac -> :ok
_ -> {:error, :invalid_hmac}
end)
Expand Down
4 changes: 4 additions & 0 deletions lib/shopify_api/security.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
defmodule ShopifyAPI.Security do
require Logger

def base16_sha256_hmac(text, secret) do
Logger.warning("Hmac passed into ShopifyAPI.Security is #{text}")

:sha256
|> hmac(secret, text)
|> Base.encode16()
Expand Down

0 comments on commit 034aaf3

Please sign in to comment.