Skip to main content

Keycloak API Client for integrating authentication and authorization with FastAPI

Project description

# FastAPI Keycloak Integration

![Py3.8](https://img.shields.io/badge/-Python%203.8-brightgreen) ![Py3.9](https://img.shields.io/badge/-Python%203.9-brightgreen) ![Py3.10](https://img.shields.io/badge/-Python%203.10-brightgreen)

## Introduction

Welcome to fastapi-keycloak. This projects goal is to ease the integration of Keycloak (OpenID Connect) with Python, especially FastAPI. FastAPI is not necessary but is encouraged due to specific features. Currently, this package supports only the password and the authorization_code. However, the get_current_user() method accepts any JWT that was signed using Keycloak´s private key.

## Docs

Docs are available at [https://fastapi-keycloak.code-specialist.com/](https://fastapi-keycloak.code-specialist.com/).

## TLDR

FastAPI Keycloak enables you to do the following things without writing a single line of additional code:

  • Verify identities and roles of users with Keycloak

  • Get a list of available identity providers

  • Create/read/delete users

  • Create/read/delete roles

  • Create/read/delete/assign groups (recursive). Thanks to @fabiothz

  • Assign/remove roles from users

  • Implement the password or the authorization_code flow (login/callback/logout)

## Contributions

We would like encourage anyone using this package to contribute to its improvement, if anything isn’t working as expected or isn’t well enough documented, please open an issue or a pull request. Please note that for any code contribution tests are required.

### Testing

Tests are stored and executed in ./tests. To test the package, it is necessary to use the start_infra.sh script upfront, to set up Keycloak and Postgres. We do this to avoid artificial testing conditions that occur by mocking all the keycloak requests. The issue here is that we currently see no way to offer public testing opportunities without significant security issues, which is why you have to run these tests locally and provide a test_coverage.xml file. The test coverage is configured in the pytest.ini and will be created once the tests finished running (locally).

## Original authors

Shoutout to the original authors of this project:

  • Yannic Schröer @yannicschroeer

  • Jonas Scholl @JonasScholl

This project was in the [Code Specialist organization](https://github.com/code-specialist/) before being moved here.

Project details


Download files

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

Source Distribution

fastapi_keycloak-1.0.11.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

fastapi_keycloak-1.0.11-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_keycloak-1.0.11.tar.gz.

File metadata

  • Download URL: fastapi_keycloak-1.0.11.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for fastapi_keycloak-1.0.11.tar.gz
Algorithm Hash digest
SHA256 e3b4e290bfbc47077cb9bca33f6bac758216a40bfd9fe13c843c71d56087e20c
MD5 da3ef1828f67fff5ecdf3049d101f4c7
BLAKE2b-256 f0217fce6049d437ec058c21c373a89a1f81721cf7bcf299b47ce6506f9aa612

See more details on using hashes here.

File details

Details for the file fastapi_keycloak-1.0.11-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_keycloak-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 2d2da95cc9bfd2c02f80bbff3bd4ed985d398a07354da917ee4f7e6416373b29
MD5 391420df6e2f1d923f9abf670890e2b4
BLAKE2b-256 b2bd08ee05c2e39156a51790e3bf3e723f211ca302d95248ef4f7f15191f56cd

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