码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-05-26 21:21:16      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:int   api   管理   led   edit   res   检查   用户   view   

因为使用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等

 

这样,可对权限做集中管理

 

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

标签:int   api   管理   led   edit   res   检查   用户   view   

原文地址:https://www.cnblogs.com/littlehb/p/9094203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!