-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
28 lines (28 loc) · 1.06 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask import Flask,jsonify,request,send_file,json
from pyotp import *
from base64 import *
from qrcode import *
from base64 import standard_b64encode
from _io import BytesIO
app = Flask(__name__)
app.config["SECRET_KEY"] = "Flask OTP API V4"
@app.route("/getauthcode")
def get__():
dict_ = json.loads(request.get_json())
totp_ = totp.TOTP(dict_["auth_vendor_id"])
return jsonify({"code":totp_.now()})
@app.route("/createuser")
def create():
totp_ = totp.TOTP(random_base32())
outn = BytesIO()
img = make(totp_.provisioning_uri("python.access.server@gmail.com",issuer_name = "Cinara-Lyca Network Co.LTD"))
img.save(outn)
data = standard_b64encode(outn.getvalue())
data_uri = "data:image/png;base64," + data.decode()
return jsonify({"qr_code_url":data_uri,"auth_vendor_id":totp_.secret})
@app.route("/verify")
def verify():
dict_ = json.loads(request.get_json())
totp_ = totp.TOTP(dict_["auth_vendor_id"])
condition = totp_.verify(dict_["code"])
return jsonify(condition)