[Flask] Add authentication to auto generated URLs

Gergely Polonkai gergely at polonkai.eu
Wed Mar 1 16:42:54 EST 2017


As it’s a plain decorator, you can use

current_app.add_url_rule(
'secret_page_url/', view_func=auth.login_required(view_func),
methods=['POST', ])

Hint: if you need to use a decorator that requires parameters, use
something like this:

a_decorator(decor_arg, decor_arg)(view_func)

You can also nest them:

a_decorator(arg, arg)(auth.login_required(view_func))

Best,
Gergely

On Wed, Mar 1, 2017, 10:48 Christof Verdonck <
hcmr.verdonck.christof at gmail.com> wrote:

> Dear
>
>
> I am a quiet new developer for both Python and Flask.
>
>
> To authenticate my Flask application, I am using the Flask extension:
> flask-httpauth/ <http://github.com/miguelgrinberg/flask-httpauth/>
> To have a secured endpoint, I just add the @auth.login_required decorator
> to the @app.route endpoint definition as shown here under:
>
> @app.route('/secret_page')
> @auth.login_required
> def secret_page():
>     return send_from_directory(app.static_folder, 'secret_page.html')
>
>
> Now, I have some endpoints that I add dynamically as here under:
>
>
> current_app.add_url_rule(
>     'secret_page_url/', view_func=view_func, methods=['POST', ])
>
>
> I would like to add also authentication for these URLs but I can't figure out how this is done.
>
> It seems that the solution I have now, adds authentication on the adding of the rule instead
>
> of on the accessing of the URL.
>
> Can someone please give me a hint/solution how this is done?
>
>
> Thank you in advance
>
>
> Christof
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170301/1f70da78/attachment.html>


More information about the Flask mailing list