pythonflaskflask-oauthlib

How to use decorators with Flask MethodView (e.g., oauth.require_oauth)


This might be a Python newbie question (i.e., not understanding decorators).

I have a view class that I want to protect by requiring OAuth authentication (I have all of the OAuth stuff set-up and working).

The docs say do this:

@app.route('/api/user')
@oauth.require_oauth('email', 'username')
def user():
    return jsonify(request.oauth.user)

But I have a MethodView class:

@inject(oauth=OAuth)
class MyView(flask.views.MethodView):
    def get(self):
        pass

I can inject the OAuth object, but how do I use it to achieve the same effect?


Solution

  • My mistake. I think @oauth.require_oauth is meant only for OAuth providers.