uotp/helper.py
2019-10-07 22:13:42 +05:00

19 lines
No EOL
458 B
Python

import pyotp
from decouple import config
from os.path import join
def is_valid_otp(etcd_client, name, realm, token):
_key = join(config("BASE_PREFIX"), realm, name)
entry = etcd_client.get(_key, value_in_json=True)
if entry:
totp = pyotp.TOTP(entry.value['seed'])
try:
is_token_valid = totp.verify(token)
except:
return False
else:
return is_token_valid
return False