Handling Keycloak and Fastapi error messages
See original GitHub issueIssue Description
I really appreciate that you created this package. it is something I was looking for too much time ago. I have been using it and I face the following problem I see that the Keycloak exception is fired but it is not passed to fast API which shows 500 error. Do you know how can I pass the error message to Swagger?
This is the API I am trying to use:
@app.post("/users2")
def create_user(first_name: str, last_name: str, email: str, password: SecretStr):
return idp.create_user(first_name=first_name, last_name=last_name, username=email, email=email, password=password.get_secret_value(), send_email_verification=False)


Issue Analytics
- State:
- Created 9 months ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Issues · code-specialist/fastapi-keycloak - GitHub
Contribute to code-specialist/fastapi-keycloak development by creating an ... Handling Keycloak and Fastapi error messages documentation Improvements or ...
Read more >Handling Errors - FastAPI
The item the client was trying to access doesn't exist. etc. In these cases, you would normally return an HTTP status code in...
Read more >Python Keycloak Error - Public client not allowed to retrieve ...
I'm trying to get keycloak_admin instance in my code as described in documentation https://pypi.org/project ...
Read more >Build and Secure a FastAPI Server with Auth0
Learn the basics of FastAPI, how to quickly set up a server and secure ... You'll create a VerifyToken class to handle JWT...
Read more >API login and JWT token generation using Keycloak
Everything will be done using API calls, so Keycloak's UI is not exposed to ... in an HTTP 401 response code and a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You should define a custom error handler in your FastAPI app for the KeycloakError that catches the error and returns the error message:
Instead of throwing the error and raising a 500, the app should now proxy the errors as expected.
@jonra1993 Thank you for your question, we’re going to add this to the documentation
Hello, @Youssef-Harby can you try this setup using containers it worked in my case I plan in the future migrate this project to AuthN and AuthZ using keycloak it is still a work in progress, but you can check the setup and package versions.
https://github.com/jonra1993/fastapi-alembic-sqlmodel-async/blob/development/fastapi-alembic-sqlmodel-async/app/main.py