pallets-eco / flask-security

Quick and simple security for Flask applications
MIT License
1.63k stars 513 forks source link

@auth_required JSON Response #876

Open Aaron-Ochieng opened 2 years ago

Aaron-Ochieng commented 2 years ago

I need @auth_required decorator to return JSON response instead of HTML since I'm working with SPA. Can anyone help me by giving a simple example please. I'm stuck guys with the documentation.

jwag956 commented 2 years ago

If you are using flask-security-too it has a complete openapi spec: https://flask-security-too.readthedocs.io/en/stable/_static/openapi_view.html#auth

Aaron-Ochieng commented 2 years ago

Still not helping.On 20 May 2022 6:48 am, Chris Wagner @.***> wrote: If you are using flask-security-too it has a complete openapi spec: https://flask-security-too.readthedocs.io/en/stable/_static/openapi_view.html#auth

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

jwag956 commented 2 years ago

Flask-Security-Too has a default_unauthn_handler that returns JSON if the request was JSON or is asking (via Accept header). You can see more details here: https://flask-security-too.readthedocs.io/en/stable/customizing.html?highlight=auth_required#oh-my

If you are still having issues - please take the discussion over to: https://github.com/Flask-Middleware/flask-security/discussions

and provide some code that is failing.