fastapi-jwks


Namefastapi-jwks JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-11-07 12:47:27
maintainerNone
docs_urlNone
authorbakdata
requires_python<4.0,>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```sh
pip install fastapi_jwks
```

```python
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)

...
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastapi-jwks",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "bakdata",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/e1/9a/cd52e773192bc287940a5e9190e225719c75b39d7a49376567b2988860bd/fastapi_jwks-0.1.1.tar.gz",
    "platform": null,
    "description": "# fastapi-jwks\n\nfastapi-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.\n\n## Key Features\n\n- **JWKS Endpoint Querying**: The library automatically queries the JWKS endpoint to fetch the necessary keys for token verification.\n- **Token Verification**: It verifies the tokens sent over a request with the JWKS endpoint, ensuring the authenticity and integrity of the data.\n- **Middleware Integration**: The library includes a middleware that can be easily integrated into your FastAPI application to handle token validation on every request.\n- **Pydantic Model Support**: It supports Pydantic models for token data extraction, providing a seamless way to work with the token data.\n\n## Usage\n\n```sh\npip install fastapi_jwks\n```\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi import Depends\nfrom pydantic import BaseModel\nfrom fastapi_jwks.injector import JWTTokenInjector\nfrom fastapi_jwks.middlewares.jwk_auth import JWKSAuthMiddleware\nfrom fastapi_jwks.models.types import JWKSConfig, JWTDecodeConfig\nfrom fastapi_jwks.validators import JWKSValidator\n\n# The data we want to extract from the token\nclass FakeToken(BaseModel):\n    user: str\n\n\napp = FastAPI()\n\npayload_injector = JWTTokenInjector[FakeToken]()\n\n\n@app.get(\"/my-endpoint\", response_model=FakeToken)\ndef my_endpoint(fake_token: Depends(payload_injector)):\n    return fake_token\n\n\njwks_verifier = JWKSValidator[FakeToken](\n    decode_config=JWTDecodeConfig(),\n    jwks_config=JWKSConfig(url=\"http://my-fake-jwks-url/my-fake-endpoint\"),\n)\n\napp.add_middleware(JWKSAuthMiddleware, jwks_validator=jwks_verifier)\n\n...\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": null,
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53bb160f9d74dc31797caaa720e280bf206ab4c2ff2de36f3781b3656bad05a5",
                "md5": "872c4d509d232786e724ff0022627b05",
                "sha256": "8f7f013e6d0fea00bb73d158a605915443b9647ea67c1754aaf7c847f3e9484d"
            },
            "downloads": -1,
            "filename": "fastapi_jwks-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "872c4d509d232786e724ff0022627b05",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 6599,
            "upload_time": "2024-11-07T12:47:27",
            "upload_time_iso_8601": "2024-11-07T12:47:27.080581Z",
            "url": "https://files.pythonhosted.org/packages/53/bb/160f9d74dc31797caaa720e280bf206ab4c2ff2de36f3781b3656bad05a5/fastapi_jwks-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e19acd52e773192bc287940a5e9190e225719c75b39d7a49376567b2988860bd",
                "md5": "0e024e3e956478b05526945790437272",
                "sha256": "6d54f0750ad54349c6a13640f981020aee5314ee769cf8cec2bea55e7d1254e9"
            },
            "downloads": -1,
            "filename": "fastapi_jwks-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0e024e3e956478b05526945790437272",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 4948,
            "upload_time": "2024-11-07T12:47:27",
            "upload_time_iso_8601": "2024-11-07T12:47:27.973258Z",
            "url": "https://files.pythonhosted.org/packages/e1/9a/cd52e773192bc287940a5e9190e225719c75b39d7a49376567b2988860bd/fastapi_jwks-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-07 12:47:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fastapi-jwks"
}
        
Elapsed time: 0.40239s