Flask-Multipass-Keycloak
This package provides the keycloak authentication and identity providers for Flask-Multipass.
KeycloakAuthProvider
This provider is a simple wrapper around AuthlibAuthProvider, since Keycloak works well with the standard authlib provider in flask-multipass.
KeycloakIdentityProvider
This provider gives access to group information and members via Keycloak REST API.
Install
pip install flask-multipass-keycloak
Usage
Configuration
The configuration follows the standard Flask-Multipass way and the Keycloak specific part placed into the keycloak_args section.
MULTIPASS_AUTH_PROVIDERS = {
'keycloak': {
'type': 'keycloak',
'title': 'Keycloak Auth Provider',
'authlib_args': {...}
}
}
MULTIPASS_IDENTITY_PROVIDERS = {
'keycloak': {
'type': 'keycloak',
'title': 'Keycloak Identity Provider',
'identifier_field': 'email',
'keycloak_args': {
'grant_type': 'client_credentials',
'client_id': '<client_id>',
'client_secret': '<client_secret>',
'access_token_url': '<access-token-url>',
'realm_api_url': '<realm-api-url>'
}
}
}
The configuration values are following:
-
grant_typeDefault value is
client_credentials. In Keycloak, "Service accounts roles" must be enabled in client config (Client details/Settings/Capability).passwordis also supported. In Keycloak, "Direct access grants" must be enabled in client config (Client details/Settings/Capability). In this case 2 additional fields must be added:usernameandpassword. -
client_idIn Keycloak, Client details/Setting/Client ID field.
-
client_secretIn Keycloak, Client details/Credentials/Client Secret field.
-
access_token_urlIn Keycloak, Realm settings/General/Endpoints/OpenID Endpoint Configuration/"token_endpoint".
-
realm_api_urlThe URL format is
<base url>/admin/realms/<realm name>, where the realm is where the users and user groups are configured.
Performance
The library needs to get an API access token from Keycloak which typically takes 200-300ms. Set the cache key of the multipass identity provider configuration to the import path of a Flask-Caching instance or a function returning such an instance, or the instance itself to enable caching of tokens (until they expire) and group data (30 minutes).
Development
In order to develop flask-multipass-keycloak, install the project and its dependencies in a virtualenv. This guide assumes that you have the following tools installed and available in your path:
git(available in most systems)make(available in most systems)poetry(installation guide)pyenv(installation guide)
First, clone the repository locally with:
git clone https://github.com/unconventionaldotdev/flask-multipass-keycloak
cd flask-multipass-keycloak
Before creating the virtualenv, make sure to be using the same version of Python that the development of the project is targeting. This is the first version specified in the .python-version file and you can install it with pyenv:
pyenv install
You may now create the virtualenv and install the project with its dependencies in it with poetry:
poetry install
Contributing
This project uses GitHub Actions to run the tests and linter on every pull request. You are still encouraged to run the tests and linter locally before pushing your changes.
Run linter checks with:
poetry run -- make lint
Run tests with:
poetry run -- make test
Run tests against all supported Python versions with:
tox
Metadata
Release files for Flask-Multipass-Keycloak 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_multipass_keycloak-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Release files / flask_multipass_keycloak-0.1.2-py3-none-any.whl
| Download URL | flask_multipass_keycloak-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3bf9f64b734261444dfba5aecc1a279c4c8d11b6537d83c20a89af5d971881b
|
|
BLAKE2b-256 checksum How to use checksums |
3973ba06fb35daea8186573cb4a9bf39aa0abe4475e8cb6a528e00540babfe5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 19, 2024.
Transparency log