Skip to main content

Keycloak API Client for integrating authentication and authorization with FastAPI

Project description

FastAPI Keycloak Integration

Test-Suite CodeFactor codecov Py3.8 Py3.9 Py3.10 CodeQL


Notice - 📢 LOOKING FOR MAINTAINERS 📢

We created this as an open-source project in order to share our code with other people. Unfortunately we decided to abandon Keycloak in our project due to its unreliability in API compatibility and the general maintenance overhead. Therefore, we are no longer able to frequently update this library. We are searching for someone or a group of people to maintain this repository actively, as we do not have the capacity but think that keycloak still is a highly relevant IDP solution. If you or your team want to take over the responsibility, please mail us at admin@code-specialist.com

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/.

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).

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.10.tar.gz (67.4 kB view details)

Uploaded Source

Built Distribution

fastapi_keycloak-1.0.10-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_keycloak-1.0.10.tar.gz
  • Upload date:
  • Size: 67.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.30.0

File hashes

Hashes for fastapi_keycloak-1.0.10.tar.gz
Algorithm Hash digest
SHA256 780e3339d19fde13aa40d29bc3acba2b505ae51263b04f5eea6fe0c4855df6b5
MD5 5bfb1b7d26e3cd2465874f817f380d6c
BLAKE2b-256 3547032629fb79abcf7a9bc9a4423d0cc8bd9c7dfd6cd0f5389f33ea9ebed329

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_keycloak-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 4d9f189414db1bb029fbb0688b32de854da3e17edd0875c549ceaabef4e3e212
MD5 cc0dd65b095ddc0fc1f30936f82bcf72
BLAKE2b-256 41b8d7d6e0a04e581a408ec4407763d99df81c3dc91ddd26054c2e0f77fbd9e4

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