富丽堂皇的酒瓶

2024-10-01 02:35:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要为我的Flask RESTful应用程序使用Autho0。Auth0有一个对视图函数使用requires_auth修饰符的example。在

@app.route('/secured/ping')
@cross_origin(headers=['Content-Type', 'Authorization'])
@requires_auth
def securedPing():
    return "All good. You only get this message if you're authenticated"

对于flaskrestful,我将add_resourceResource类一起使用,而不是将{}与视图函数一起使用。如何将requires_auth应用于Version?在

^{pr2}$

Tags: 函数auth视图restfulapp应用程序flaskexample
1条回答
网友
1楼 · 发布于 2024-10-01 02:35:29

flaskrestful文档描述了如何specify decorators for a resource。在

There is a property on the Resource class called method_decorators. You can subclass the Resource and add your own decorators that will be added to all method functions in resource.

class AuthResource(Resource):
    method_decorators = [requires_auth]

# inherit AuthResource instead of Resource to define Version

相关问题 更多 >