PostgreSQL authentication and authorization using Keycloak and FastAPI


I have developed a code using Python and SQLAlchemy to read, insert and query data from a Postgresql database.

I have also seen how to get access tokens, create roles, create clients and assign roles to users in Keycloak using FastAPI end points.

My question is how do I authorize users to use the database and giving only select roles. For example allow a user only to query data, or another user to only add data.

I’m kinda stuck and unable to see how I can get this done in Keycloak and authorize users for database operation roles.

Any tips or advice would be helpful. Thank you