19 lines
458 B
Python
19 lines
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
|