'Decorator that sets up for OAuth 2.0 dance, but doesn\'t do it.
Does all the setup for the OAuth dance, but doesn\'t initiate it.
This decorator is useful if you want to create a page that knows
whether or not the user has granted access to this application.
From within a method decorated with @oauth_aware the has_credentials()
and authorize_url() methods can be called.
Args:
method: callable, to be decorated method of a webapp.RequestHandler
instance.'

def oauth_aware(self, method):

    def setup_oauth(request_handler, *args, **kwargs):
        if self._in_error:
            self._display_error_message(request_handler)
            return
        user = users.get_current_user()
        if (not user):
            request_handler.redirect(users.create_login_url(request_handler.request.uri))
            return
        self._create_flow(request_handler)
        self.flow.params['state'] = request_handler.request.url
        self.credentials = StorageByKeyName(CredentialsModel, user.user_id(), 'credentials').get()
        method(request_handler, *args, **kwargs)
    return setup_oauth
