antarctica / flask-entra-auth

Flask extension for authenticating and authorising requests using the Entra identity platform.
https://pypi.org/project/flask-entra-auth/
MIT License
46 stars 20 forks source link

Example using blueprints #34

Closed krisnashaypp closed 4 weeks ago

krisnashaypp commented 4 weeks ago

Hi, thanks for your great library. I was wondering if you have an example how you can decorate endpoints that exist in other files and are imported into the entrypoint using blueprints? Thanks again.

felnne commented 4 weeks ago

Hi @krisnashaypp - not to hand but of the top of my head, if you use current_app you should be able to access the auth object of that for the decorator.

I haven't tried that however and it would be a good idea to include that as an example so I'll try and add something later.

krisnashaypp commented 4 weeks ago

Thanks @felnne

I think I managed to get it working in a slightly different way, I tried with current_app but it didn't work out of the box . Do you see any issues with this solution?

No reference to the lib inside where the flask app is instantiated

in extensions.py

from flask_entra_auth.resource_protector import EntraResourceProtector

auth = EntraResourceProtector()

in endpoint file

from extensions import auth

bp = Blueprint('example', __name__, url_prefix='/example')

@bp.route("/", methods=["GET"])
@auth()
def get_something():
    #something
felnne commented 4 weeks ago

@krisnashaypp, I think that would be fine - and having seen your implementation, am reminded that's how I think Flask intends extensions to be used so 👍.