I am using pytotp with flask.
Here is my basic code
@app.route('/get-otp-secret',methods=['POST'])
def getOTPSecret():
return make_response(jsonify(generate_otp_secret()),201)
@app.route('/verify-otp',methods=['POST'])
def verifyOTP():
print(request.form)
otp,secret = request.form.get('otp'),request.form.get('secret')
return jsonify(verify(otp,secret))
def generate_otp_secret():
secret = pyotp.random_base32()
t = pyotp.TOTP(secret,interval=60)
otp = t.now()
print(t.verify(otp))
return {
'secret':secret,
'otp':otp
}
def verify(otp,secret):
if pyotp.TOTP(secret).verify(otp):
return True
return False
Now, to check whether my secret and otp are same as generated I printed them.. and every thing is same.But pytotp is not verifying the otp. I there is something wrong in my method please tell me a correct way to implement pyotp. I am sending request to flask from retrofit android studio java. Thanks for helping me!!