0

I would to use an API on a website but this service is restricting some API methods with a 2FA. I really need to programmaticly call this restricted methods every 10 minutes interval.

I would to use a python script to get the time base verification code like Google Authenticator give us... but solutions given here does not give me the same code with my mobile device and with python script.

Here is the source code of the "Google Authenticator" project , but it is Java ... and I need (prefer) python !

My question is : where can I found a python script to generate exactly the same code.

Thanks in advance

A STEFANI
  • 6,434
  • 1
  • 21
  • 41
  • Are you looking for a 2FA that sends the user an SMS or Voice call which prompts them to enter a code? – Sidharth Sharma Aug 21 '15 at 17:53
  • No, I am looking for a python script that give me the same exact code like I see on my mobile with the google authenticator android app. Best regards. – A STEFANI Aug 22 '15 at 19:02

1 Answers1

0

Finally it is working with python3 using https://github.com/pyotp/pyotp/tree/master/src/pyotp example:

from pyotp.hotp import HOTP
import time

hotp=HOTP()

secret_KEY="12345678901234567890123456789012"

while 1:

   time.sleep(0.5)
   print(hotp.counter_from_time())
   hotp.generate_code_from_time(secret_key=secret_KEY, code_length=6, period=30)

which give:

(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 7.0)
('079310', 23)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 8.0)
('079310', 22)
(b'\x00\x00\x00\x00\x03\n\x90\x90', 9.0)
('079310', 21)

[...]
A STEFANI
  • 6,434
  • 1
  • 21
  • 41