This repository illustrates how we can integrate keycloak with fastAPI for authetification. This repo can be used as a template/code base for your app .
I used pipenv
for my env setup.
- install
pipenv
- install dependencies using
pipenv install
- run keycloak instance using:
docker run -p 8080:8080 -v ./keycloak/keycloak_data:/opt/keycloak/data/h2 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:22.0.3 start-dev
- now you can run your fastAPI app using
pipenv run python main.py
- access to fastAPI swagger using http://127.0.0.1:8081/docs
- get token using authorize
- make your query for
/secure