Skip to main content

A library designed to facilitate the integration of JSON Web Key Set (JWKS) with FastAPI applications

Project description

fastapi-jwks

fastapi-jwks is a Python library designed to facilitate the integration of JSON Web Key Set (JWKS) with FastAPI applications. It provides a set of tools to automatically query the JWKS endpoint and verify the tokens sent over a request.

Key Features

  • JWKS Endpoint Querying: The library automatically queries the JWKS endpoint to fetch the necessary keys for token verification.
  • Token Verification: It verifies the tokens sent over a request with the JWKS endpoint, ensuring the authenticity and integrity of the data.
  • Middleware Integration: The library includes a middleware that can be easily integrated into your FastAPI application to handle token validation on every request.
  • Pydantic Model Support: It supports Pydantic models for token data extraction, providing a seamless way to work with the token data.

Usage

pip install fastapi_jwks
from fastapi import FastAPI
from fastapi import Depends
from pydantic import BaseModel
from fastapi_jwks.injector import JWTTokenInjector
from fastapi_jwks.middlewares.jwk_auth import JWKSAuthMiddleware
from fastapi_jwks.models.types import JWKSConfig, JWTDecodeConfig
from fastapi_jwks.validators import JWKSValidator

# The data we want to extract from the token
class FakeToken(BaseModel):
    user: str


app = FastAPI()

payload_injector = JWTTokenInjector[FakeToken]()


@app.get("/my-endpoint", response_model=FakeToken)
def my_endpoint(fake_token: Depends(payload_injector)):
    return fake_token


jwks_verifier = JWKSValidator[FakeToken](
    decode_config=JWTDecodeConfig(),
    jwks_config=JWKSConfig(url="http://my-fake-jwks-url/my-fake-endpoint"),
)

app.add_middleware(JWKSAuthMiddleware, jwks_validator=jwks_verifier)

...

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_jwks-0.2.0.tar.gz (5.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_jwks-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_jwks-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi_jwks-0.2.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for fastapi_jwks-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6b782e91c5912cc6be2093f56852a35b0aa886819413cc4979f6f4914db00006
MD5 e277251ced04093a6a727fa723150d87
BLAKE2b-256 31ca9e38b2b4aa4ac3cf3c833b2182964284bd2e8f991e7bc2ec5f75bf15e4ab

See more details on using hashes here.

File details

Details for the file fastapi_jwks-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_jwks-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for fastapi_jwks-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 135680201e4852aff1696f187a0bfaa3a3b551d86557028f874973dd69e3146b
MD5 eaa80aa1ccf96fd201884505d21f7d11
BLAKE2b-256 29d1af09c4adc2003d47aa0a4f02a5096cf476e53a04ef77dede0cb8a2eb8a08

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