Skip to content
Permalink
Browse files
Add a feature to print out a URL for a QR code for the give TOTP
seed/name. Copy/pasting that into a browser will provide a QR code to
scan into a phone's OTP app.
  • Loading branch information
gstein committed Oct 14, 2020
1 parent ecb14d8 commit a435ced0836439f048636a51312ca4ec39112f1c
Showing 1 changed file with 7 additions and 1 deletion.
8 otp.py
@@ -24,6 +24,7 @@
PASSWORD_LEN = 20

ALGO_TOTP = 'totp'
TOTP_QR_GEN = 'https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=otpauth://totp/ASF%%20Infra?secret=%s&issuer=ASF'


def otp_path():
@@ -163,6 +164,8 @@ def main():
parser = argparse.ArgumentParser(description='Compute OTP strings.')
parser.add_argument('--test', help='Run the test suite.', nargs=0,
action=RunTests)
parser.add_argument('--qr', help='Print a URL for a QR code',
action='store_true')
parser.add_argument('args', nargs=argparse.REMAINDER)

# Note: this may exit, if tests are run.
@@ -217,7 +220,10 @@ def main():
assert processor, 'Unknown/unsupported algorithm: "%s"' % (algo,)

if algo == ALGO_TOTP:
response = processor(pwd)
if parsed.qr:
response = TOTP_QR_GEN % (pwd.decode(),)
else:
response = processor(pwd)
else:
value = processor(seed + pwd, seq)
response = ' '.join(to_words(value))

0 comments on commit a435ced

Please sign in to comment.