You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was recently writing some testing for an authorization plug that I wrote that uses the ExTwilio.RequestValidator and could not find a module or method that can create a x-twilio-token to put to my tests Plug.Conn header.
I propose we take this functionality that builds the token in the validator and make a module that creates a twilio signature if you pass in say url and params which may making unit testing controllers and plugs that are using the validator easier!
def create_signature(url, params) do
token = Config.auth_token()
url
|> data_for(params)
|> compute_hmac(token)
|> Base.encode64()
end
defp data_for(url, params), do: url <> combine(params)
defp combine(params) do
params
|> Map.to_list()
|> Enum.sort()
|> Enum.map(fn {key, value} -> key <> value end)
|> Enum.join()
end
defp compute_hmac(data, key), do: :crypto.hmac(:sha, key, data)
The text was updated successfully, but these errors were encountered:
I was recently writing some testing for an authorization plug that I wrote that uses the ExTwilio.RequestValidator and could not find a module or method that can create a
x-twilio-token
to put to my tests Plug.Conn header.I propose we take this functionality that builds the token in the validator and make a module that creates a twilio signature if you pass in say
url
andparams
which may making unit testing controllers and plugs that are using the validator easier!The text was updated successfully, but these errors were encountered: