我将用户标识存储在令牌中,我正在验证令牌,然后在获取用户标识后验证用户是否在 mysql db 中启用。因此,对于其他表,我也需要用户 ID 进行数据库查询,那么如何在这些函数中获取用户 ID?有没有办法获取有效负载并获取身份。主文件
app.secret_key = "temp"
api = Api(app)
jwt = JWT(app,authenticate, identity) #/auth automatically
安全.py
def authenticate(username, password):
user = User.find_by_username(username)
if user and user.password == password:
return user
def identity(payload):
user_id = payload["identity"]
return User.find_by_userid(user_id)
用户文件
def find_by_userid(cls,_id):
#db connection
query = "select uid from users where uid= %s"
消息文件
#i want user id in this function as well
def fetch_msg_(cls,uid):