Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

@auth_required JSON Response #876

Open
Aaron-Ochieng opened this issue May 18, 2022 · 3 comments
Open

@auth_required JSON Response #876

Aaron-Ochieng opened this issue May 18, 2022 · 3 comments

Comments

@Aaron-Ochieng
Copy link

Aaron-Ochieng commented May 18, 2022

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
Copy link
Collaborator

jwag956 commented May 20, 2022

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
Copy link
Author

Aaron-Ochieng commented May 20, 2022 via email

@jwag956
Copy link
Collaborator

jwag956 commented May 20, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants