使用before_request来做权限和用户检查

因为使用restful方式,因此每次用户访问都会上传带入auth_key,如jwt等,因此可在@app.before_request中做权限的检查。

@app.app.before_request
def before_request():
    #可在此处检查jwt等auth_key是否合法,
    #abort(401)
    #然后根据endpoint,检查此api是否有权限,需要自行处理
    #print(["endpoint",connexion.request.url_rule.endpoint])
    #abort(401)
    #也可做ip检查,以阻挡受限制的ip等
这样,可对权限做集中管理

猜你喜欢

转载自www.cnblogs.com/littlehb/p/9094203.html
今日推荐