You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that when the middleware returns a 403 Forbidden response, it only returns a plain text response:
"Forbidden"
However, in many cases, it would be preferable if the response was in JSON format or, at the very least, if the middleware respected the Accept header provided by the client. This would allow clients to specify the desired response format.
For example, the response could look like this when returning JSON:
{
"detail": "Forbidden"
}
I believe this would enhance the flexibility of the middleware, especially when working with modern APIs that commonly expect JSON responses.
Workaround
In my case, I have used the following workaround to return a JSON response instead of plain text:
And this workaround returns the following JSON structure:
{
"detail": "Forbidden"
}
I think this feature could be valuable to many users. I'd be happy to contribute by submitting a pull request if this improvement aligns with the project's direction.
Let me know what you think!
Best regards,
The text was updated successfully, but these errors were encountered:
Hello,
I've noticed that when the middleware returns a 403 Forbidden response, it only returns a plain text response:
However, in many cases, it would be preferable if the response was in JSON format or, at the very least, if the middleware respected the Accept header provided by the client. This would allow clients to specify the desired response format.
For example, the response could look like this when returning JSON:
I believe this would enhance the flexibility of the middleware, especially when working with modern APIs that commonly expect JSON responses.
Here's the current implementation of the middleware:
https://github.com/pycasbin/fastapi-authz/blob/master/fastapi_authz/middleware.py
Workaround
In my case, I have used the following workaround to return a JSON response instead of plain text:
And this workaround returns the following JSON structure:
I think this feature could be valuable to many users. I'd be happy to contribute by submitting a pull request if this improvement aligns with the project's direction.
Let me know what you think!
Best regards,
The text was updated successfully, but these errors were encountered: