flask-security icon indicating copy to clipboard operation
flask-security copied to clipboard

@auth_required JSON Response

Open Aaron-Ochieng opened this issue 3 years ago • 3 comments

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.

Aaron-Ochieng avatar May 18 '22 18:05 Aaron-Ochieng

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

jwag956 avatar May 20 '22 03:05 jwag956

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: @.***>

Aaron-Ochieng avatar May 20 '22 14:05 Aaron-Ochieng

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.

jwag956 avatar May 20 '22 15:05 jwag956