Guys I need to use Flask-RESTful API with Flask-User. The way of using flask restful is below
from flask import Flask from flask_restful import Resource, Api app = Flask(__name__) api = Api(app) class HelloWorld(Resource): def get(self): return {'hello': 'world'} api.add_resource(HelloWorld, '/') if __name__ == '__main__': app.run(debug=True)
whereas the way for using Role-based Authorization in Flask-User is below
from flask_user import roles_required @route('/admin/dashboard') # @route() must always be the outer-most decorator @roles_required('Admin') def admin_dashboard(): # render the admin dashboard
Cleary flask restful doesn't involve decorators for routes above functions, instead it involves resources. And flask user provides role based authorization in the form of decorators above the same functions not present in flask. So how can I use such role-based-authorization of Flask User with Flask restful ?
Asked
Active
Viewed 349 times
2

Arsalan Ahmad Ishaq
- 877
- 8
- 15
1 Answers
0
Sorry for that, I just learned what decorator functions are and it seems that this can be achieved using
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
@roles_required('Admin')
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')
if __name__ == '__main__':
app.run(debug=True)
That is simply pass the get and other methods into the decorators from Flask-User

Arsalan Ahmad Ishaq
- 877
- 8
- 15