preparation for 2fa

This commit is contained in:
Mylloon 2023-05-14 01:57:29 +02:00
parent 85c20935c0
commit 4a2db80c54
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 15 additions and 5 deletions

View file

@ -22,7 +22,7 @@ $ opam switch list
``` ```
```sh ```sh
$ opam install cohttp-lwt-unix tls-lwt dotenv $ opam install cohttp-lwt-unix tls-lwt dotenv twostep
``` ```
## Name history ## Name history

View file

@ -2,4 +2,4 @@
(public_name pusk) (public_name pusk)
(name main) (name main)
(modules main twitter) (modules main twitter)
(libraries pusk)) (libraries pusk twostep))

View file

@ -25,7 +25,7 @@ let main ctx =
| None, Some _ -> raise (Any "Username not set") | None, Some _ -> raise (Any "Username not set")
| Some _, None -> raise (Any "Password not set") | Some _, None -> raise (Any "Password not set")
in in
login_twitter ctx username password login_twitter ctx username password (Sys.getenv_opt "TWITTER_TOTP")
;; ;;
let () = let () =

View file

@ -1,7 +1,8 @@
open Pusk.Net open Pusk.Net
open Pusk.Utils 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*) (* Navigate to login page and wait for page loaded*)
ignore (navigate ctx.session_id "https://twitter.com/i/flow/login"); ignore (navigate ctx.session_id "https://twitter.com/i/flow/login");
Unix.sleep 5; Unix.sleep 5;
@ -42,5 +43,14 @@ let login_twitter ctx username password =
send_keys ctx.session_id input_password password; send_keys ctx.session_id input_password password;
Unix.sleep 1; Unix.sleep 1;
send_keys ctx.session_id input_password Keys.return; 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 *)
()
;; ;;