     end
   end
 
-  def authorize_with_secret(email, secret, server) do
+  def authorize_with_secret(email, secret, server, state \\ %{backoff: 5000, logged_once: false})
+
+  def authorize_with_secret(email, secret, server, state) do
     with {:ok, payload} <- build_payload(secret),
          {:ok, resp}    <- request_token(server, payload),
          {:ok, body}    <- Poison.decode(resp),

      Map.fetch(map, "encoded")
    else
      :error -> {:error, "unknown error."}
      {:error, :invalid, _} -> authorize(email, secret, server)
      # If we got maintance mode, a 5xx error etc,
      # just sleep for a few seconds
      # and try again.
      {:error, {:http_error, code}} ->
        Logger.error 1, "Failed to authorize due to server error: #{code}"
        Process.sleep(5000)
        authorize(email, secret, server)
      {:error, %HTTPoison.Error{reason: reason}} -> {:error, reason}
      err -> err
    end

      # If we got maintance mode, a 5xx error etc,
      # just sleep for a few seconds
      # and try again.
      {:error, {:http_error, code}} ->
        Logger.error 1, "Failed to authorize due to server error: #{code}"
        Process.sleep(5000)
