A minimal working example demonstrating how to secure a FastAPI application using Keycloak for authentication and authorization via OAuth2/OpenID Connect.
docker compose upThis will spin up both Keycloak and the FastAPI app.
- Open Keycloak at http://localhost:8080
Login with:
- Username:
admin - Password:
admin
- Create a new client with the following settings:
- Client ID:
example - Valid Redirect URIs:
http://localhost:5001/ - Post Logout Redirect URIs:
http://localhost:5001/ - Web Origins:
* - Enable Standard Flow
- PKCE Method:
S256
Once everything is running:
- Visit the FastAPI app at http://localhost:5001
The app should redirect you to Keycloak for login and then back to the FastAPI app once authenticated.