From 4a2db80c54c8e129a9b76304bb4467f8e7200b97 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 14 May 2023 01:57:29 +0200 Subject: [PATCH] preparation for 2fa --- README.md | 2 +- bin/dune | 2 +- bin/main.ml | 2 +- bin/twitter.ml | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0c16d4f..b2c7972 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ opam switch list ``` ```sh -$ opam install cohttp-lwt-unix tls-lwt dotenv +$ opam install cohttp-lwt-unix tls-lwt dotenv twostep ``` ## Name history diff --git a/bin/dune b/bin/dune index db6c5b1..6943e4e 100644 --- a/bin/dune +++ b/bin/dune @@ -2,4 +2,4 @@ (public_name pusk) (name main) (modules main twitter) - (libraries pusk)) + (libraries pusk twostep)) diff --git a/bin/main.ml b/bin/main.ml index 80147cd..f1fa0d1 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -25,7 +25,7 @@ let main ctx = | None, Some _ -> raise (Any "Username not set") | Some _, None -> raise (Any "Password not set") in - login_twitter ctx username password + login_twitter ctx username password (Sys.getenv_opt "TWITTER_TOTP") ;; let () = diff --git a/bin/twitter.ml b/bin/twitter.ml index 34bd121..6e7fd54 100644 --- a/bin/twitter.ml +++ b/bin/twitter.ml @@ -1,7 +1,8 @@ open Pusk.Net open Pusk.Utils +(* open Twostep *) -let login_twitter ctx username password = +let login_twitter ctx username password _secret = (* Navigate to login page and wait for page loaded*) ignore (navigate ctx.session_id "https://twitter.com/i/flow/login"); Unix.sleep 5; @@ -42,5 +43,14 @@ let login_twitter ctx username password = send_keys ctx.session_id input_password password; Unix.sleep 1; send_keys ctx.session_id input_password Keys.return; - Unix.sleep 5 + Unix.sleep 5; + (* Detection of 2FA *) + (* TODO *) + (* Generate code if possible *) + (* let code = + match secret with + | Some seed -> Twostep.TOTP.code ~secret:seed () + | None -> raise (Any "No TOTP code given, but TOTP required") + in *) + () ;;