flask-simpleldap
flask-simpleldap copied to clipboard
ldap.group_required doesn't work as decorator when listed in API from Flask-Restplus
I came across this issue where the ldap.group_required doesn't work as decorator when it is listed in API which has a blueprint from flask-restplus.
from flask import Blueprint
from clients.routes import api as ns1
from configurations.custom_api import CustomAPI
class Blueprints:
def __init__(self):
pass
@staticmethod
def blueprint_swagger(ldap=None):
blueprint = Blueprint('api', __name__, url_prefix='/api/v1')
api = CustomAPI(blueprint,
title='Hello World',
version='1.0',
description='Random Description',
decorators=[ldap.group_required(groups=['GROUP1']), ldap.basic_auth_required])
api.add_namespace(ns1)
return blueprint
The CustomAPI Class is defined as follows:
from flask import url_for
from flask_restplus import Api
class CustomAPI(Api):
@property
def specs_url(self):
"""
The Swagger specifications absolute url (ie. `swagger.json`)
:rtype: str
"""
return url_for(self.endpoint('specs'), _external=False)
the error i received while doing this is
Traceback (most recent call last):
File "PATH/venv/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "PATH/venv/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "PATH/venv/lib/python3.7/site-packages/flask_simpleldap/__init__.py", line 321, in wrapped
if g.user is None:
File "PATH/venv/lib/python3.7/site-packages/werkzeug/local.py", line 348, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute 'user'
Would appreciate a quick response.