title: Flask-restful API Authorization. Access current_identity inside decorator
body: <p>I use flask-restful to create my APIs. I have used <code>flask-jwt</code> for enabling authentication based on <code>JWT</code>. Now I need to do authorization.</p>
  
  <p>I have tried putting my authorization decorator. </p>
  
  <p><strong>test.py (/test api)</strong></p>
  
  <pre><code>from flask_restful import Resource
  from flask_jwt import jwt_required
  
  from authorization_helper import authorized_api_user_type
  
  
  class Test(Resource):
  
      decorators = [jwt_required(), authorized_api_user_type()]
  
      def get(self):
          return 'GET OK'
  
      def post(self):
          return 'POST OK'
  </code></pre>
  
  <p>Basically to handle the basic authorization, I need to access <code>current_identity</code> and check it's type. Then based on it's type I am gonna decide whether the user is authorized to access the api / resources.</p>
  
  <p>But <code>current_identity</code> appears to be <code>empty</code> in that decorator. So to get it indirectly, I had to see the code of <code>jwt_handler</code> and do the things done there. </p>
  
  <p><strong>authorization_helper.py</strong></p>
  
  <pre><code>from functools import wraps
  from flask_jwt import _jwt, JWTError
  import jwt
  from models import Teacher, Student
  
  def authorized_api_user_type(realm=None, user_type='teacher'):
      def wrapper(fn):
          @wraps(fn)
          def decorator(*args, **kwargs):
              token = _jwt.request_callback()
  
              if token is None:
                  raise JWTError('Authorization Required', 'Request does not contain an access token',
                                 headers={'WWW-Authenticate': 'JWT realm="%s"' % realm})
  
              try:
                  payload = _jwt.jwt_decode_callback(token)
              except jwt.InvalidTokenError as e:
                  raise JWTError('Invalid token', str(e))
  
              identity = _jwt.identity_callback(payload)
              if user_type == 'student' and isinstance(identity, Student):
                  return fn(*args, **kwargs)
              elif user_type == 'teacher' and isinstance(identity, Teacher):
                  return fn(*args, **kwargs)
              # NOTE - By default JWTError throws 401. We needed 404. Hence status_code=404
              raise JWTError('Unauthorized',
                             'You are unauthorized to request the api or access the resource',
                             status_code=404)
          return decorator
      return wrapper
  </code></pre>
  
  <p>Why can't I just access <code>current_identity</code> in my <code>authorized_api_user_type</code> decorator? What is the RIGHT way of doing authorization in flask-restful?</p>