
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
fastapi-keycloak-middleware
Advanced tools
Full documentation is available at Read The Docs
This package provides a middleware for FastAPI that simplifies integrating with Keycloak for authentication and authorization. It supports OIDC and supports validating access tokens, reading roles and basic authentication. In addition it provides several decorators and dependencies to easily integrate into your FastAPI application.
It relies on the python-keycloak package, which is the only dependency outside of the FastAPI ecosystem which would be installed anyway. Shoutout to the author of fastapi-auth-middleware which served as inspiration for this package and some of its code.
In the future, I plan to add support for fine grained authorization using Keycloak Authorization services.
Using FastAPI and Keycloak quite a lot, and keeping to repeat myself quite a lot when it comes to authentiating users, I decided to create this library to help with this.
There is a clear separation between the authentication and authorization:
Install the package using poetry:
poetry add fastapi-keycloak-middleware
or pip
:
pip install fastapi-keycloak-middleware
The package helps with:
This package is heavily inspired by fastapi-auth-middleware which provides some of the same functionality but without the direct integration into Keycloak. Thanks for writing and providing this great piece of software!
The client is written in pure Python. Any changes or pull requests are more than welcome, but please adhere to the code style.
Ruff is used both for code formatting and linting. Before committing, please run the following command to ensure that your code is properly formatted:
ruff check .
ruff format .
A pre-commit hook configuration is supplied as part of the project.
This project is using Act to handle local development tasks. It is used to work locally and also to test Github actions before deploying them.
FAQs
Middleware for FastAPI to authenticate a user against keycloak
We found that fastapi-keycloak-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.