Skip to main content

Keycloak API Client for integrating authentication and authorization with FastAPI

Project description

FastAPI Keycloak Integration

Py3.9 Py3.10 Py3.11 Py3.12

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

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_keycloak-1.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_keycloak-1.1.1.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastapi_keycloak-1.1.1.tar.gz
Algorithm Hash digest
SHA256 81a3166257375de73b3ef8b9d7b402733c6c9401ce1f009464fba2e53d7a1cd4
MD5 d9d4d8924faabab7baa6f68f7220be8e
BLAKE2b-256 f71605ca4a6f85d66b523f048a24995102add4fad2e6ec2bd67cea707ff379b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_keycloak-1.1.1.tar.gz:

Publisher: publish.yml on fastapi-keycloak/fastapi-keycloak

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for fastapi_keycloak-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2d36b6e2c790e8d1e496bb86a643394a635a21ff35953ae4470c1a767b66121d
MD5 23bdb2516c9085a333c2478be66ba6b1
BLAKE2b-256 75f7d83ecea7f213df8f78cd8cbf31661cb296eca8fbd0feb1d558a56d064b55

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_keycloak-1.1.1-py3-none-any.whl:

Publisher: publish.yml on fastapi-keycloak/fastapi-keycloak

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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