Skip to main content

No project description provided

Project description

FastAPI Keycloack

Keycloack plugin for FastApi.

Your aplication receives the claims decoded from the access token.

Usage

Run keycloak on port 8080 and configure your keycloack server:

docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:15.0.2

Install dependencies

pip install fastapi fastapi-keycloack uvicorn

Create the main.py module

from fastapi import Depends, FastAPI, Security

from fastapi_keycloack import JwtDecodeOptions, FastApiKeycloack, GrantType

app = FastAPI()

decode_options = JwtDecodeOptions(verify_aud=False)
allowed_grant_types = [
    GrantType.IMPLICIT,
    GrantType.PASSWORD,
    GrantType.AUTHORIZATION_CODE,
    GrantType.CLIENT_CREDENTIALS,
]

auth_scheme = FastApiKeycloack(
    url="http://localhost:8080/auth/realms/master",
    scheme_name="Keycloak",
    jwt_decode_options=decode_options,
    allowed_grant_types=allowed_grant_types,
)


def get_current_user(claims: dict = Security(auth_scheme)):
    return claims


@app.get("/users/me")
def read_current_user(claims: dict = Depends(get_current_user)):
    return claims

Run the application

uvicorn main:app

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-keycloack-0.2.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

fastapi_keycloack-0.2.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-keycloack-0.2.1.tar.gz.

File metadata

  • Download URL: fastapi-keycloack-0.2.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.14.16-arch1-1

File hashes

Hashes for fastapi-keycloack-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7c8d7eb438f4b8ae62e8472851a0a4b48a6dbc19f9041bf08e5c88692fc0d2f3
MD5 e6e700145bea964b816d3bcd25bc891c
BLAKE2b-256 68a7013cdbbbe29f31b12f0aea0d4d3d4b4a8df410d4d48f5421f9fd264c1b6e

See more details on using hashes here.

File details

Details for the file fastapi_keycloack-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_keycloack-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.5 Linux/5.14.16-arch1-1

File hashes

Hashes for fastapi_keycloack-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 022553a23f61206c709c71aca9aed0e380de17e5843327c966cbdece1983e9b7
MD5 2d9eb18283d042824e5ce6688160a10b
BLAKE2b-256 0a42fc280b587a2e4eaba1291ecb9c25fcb193a8ee1097b6e89a6cd4e73b9b77

See more details on using hashes here.

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