Commit 405ff934896ce9bd09e370590d16ef34753da323

Stephen Moloney 2017-02-16T12:22:47

fix bug for handling 2FA

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