fix bug for handling 2FA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index 6ed7472..eaaf8c3 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -351,11 +351,10 @@ defmodule Mix.Tasks.Ovh do
headers = [{"Content-Type", "application/x-www-form-urlencoded"}]
options = @default_options
resp = HTTPoison.request!(method, uri, body, headers, options)
- |> Og.log_return()
case check_for_successful_binding(resp, validation_url, ck) do
- {:ok, ck} -> ck
{:ok, :handle_2fa} -> handle_2fa(resp.body, validation_url, ck)
+ {:ok, ck} -> ck
{:error, msg} -> raise msg
end
end
@@ -403,6 +402,7 @@ defmodule Mix.Tasks.Ovh do
name_val = :proplists.get_value("name", input)
# Get value from shell asking user for 2FA code.
value = Mix.Shell.IO.prompt("Please enter *promptly* the 2FA (2 Factor Authentication) code generated by your mobile application:")
+ |> String.trim()
Mix.Shell.IO.info("The code #{value} will be sent as the 2FA code")
{name_val, value}
true ->
@@ -415,7 +415,7 @@ defmodule Mix.Tasks.Ovh do
{name_val, value} -> acc <> name_val <> "=" <> value <> "&"
end
end)
- |> String.trim_trailing("&")
+ |> Kernel.<>("otpMethod" <> "=" <> "totp")
end
@@ -424,19 +424,15 @@ defmodule Mix.Tasks.Ovh do
method = :post
uri = validation_url
- |> Og.log_return()
body = build_2fa_request(resp_body)
- |> Og.log_return(:error)
headers = [{"Content-Type", "application/x-www-form-urlencoded"}]
options = @default_options
resp = HTTPoison.request!(method, uri, body, headers, options)
- resp.body |> Og.log_return()
-
- error_msg = "Function check_for_successful_binding seems to be entering an error loop"
+ error_msg = "function check_for_successful_binding seems to be entering an error loop"
case check_for_successful_binding(resp, validation_url, ck) do
- {:ok, ck} -> ck
{:ok, :handle_2fa} -> raise error_msg
+ {:ok, ck} -> ck
{:error, msg} -> raise "#{error_msg} - #{msg}"
end
end