code: def authentify(self, func):
          '''Authentify the user if credentials are given'''
          @wraps(func)
          def wrapper(*args, **kwargs):
              if current_user.is_authenticated:
                  return func(*args, **kwargs)
  
              apikey = request.headers.get(HEADER_API_KEY)
              if apikey:
                  try:
                      user = User.objects.get(apikey=apikey)
                  except User.DoesNotExist:
                      self.abort(401, 'Invalid API Key')
  
                  if not login_user(user, False):
                      self.abort(401, 'Inactive user')
              else:
                  oauth2.check_credentials()
              return func(*args, **kwargs)
          return wrappef authentify(self, func):
          '''Authentify the user if credentials are given'''
          @wraps(func)
          def wrapper(*args, **kwargs):
              if current_user.is_authenticated:
                  return func(*args, **kwargs)
  
              apikey = request.headers.get(HEADER_API_KEY)
              if apikey:
                  try:
                      user = User.objects.get(apikey=apikey)
                  except User.DoesNotExist:
                      self.abort(401, 'Invalid API Key')
  
                  if not login_user(user, False):
                      self.abort(401, 'Inactive user')
              else:
                  oauth2.check_credentials()
              return func(*args, **kwargs)
          return wrapper
docs: Authentify the user if credentials are given