uotp/helper.py

19 lines
458 B
Python
Raw Normal View History

2019-10-07 17:13:42 +00:00
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