Skip to main content

Flask-Multipass provider for Keycloak

Project description

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': {
            'client_name': '<client_name>',
            'client_secret': '<client_secret>',
            'username': <username>,
            'password': <password>,
            'access_token_url': <access-token-url>,
            'realm_api_url': <realm-api-url>
        }
    }
}

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:

First, clone the repository locally with:

git clone https://github.com/indico/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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file flask_multipass_keycloak-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_multipass_keycloak-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84021477ce670456082b7e5e7f3e89a196b8f3213f4934a03a3d2ebcecf1324e
MD5 250acb516df92da5081b0588b17c62fb
BLAKE2b-256 5409573c82080d14219453d7342dd6e30772d9b17c7df2f6ca1d8448084d58b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page