Skip to main content

API key validation Middleware

Project description


FastAPI-key-auth

Secure your FastAPI endpoints using API keys.
Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact

About The Project

On deployment inject API keys authorized to use your service. Every call to a private endpoint of your service has to include a header['x-api-key'] attribute that is validated against the API keys in your environment. If it is present, a request is authorized. If it is not FastAPI return 401 Unauthorized. Use this either as a middleware, or as Dependency.

Built With

Getting Started

Installation

  1. Clone and install
    git clone https://github.com/iwpnd/fastapi-key-auth.git
    uv sync
    
  2. Install with pip
    pip install fastapi-key-auth
    
  3. Install with uv
    uv add fastapi-key-auth
    

Usage

As Middleware:

from fastapi import FastAPI
from fastapi_key_auth import AuthorizerMiddleware

app = FastAPI()

app.add_middleware(AuthorizerMiddleware, public_paths=["/ping"], key_pattern="API_KEY_")

# optional use regex startswith
app.add_middleware(AuthorizerMiddleware, public_paths=["/ping", "^/users"])

As Dependency

from fastapi import FastAPI, Depends
from fastapi_key_auth import AuthorizerDependency

authorizer = AuthorizerDependency(key_pattern="API_KEY_")

# either globally or in a router
app = FastAPI(dependencies=[Depends(authorizer)])

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Benjamin Ramser - @imwithpanda - ahoi@iwpnd.pw Project Link: https://github.com/iwpnd/fastapi-key-auth

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_key_auth-0.15.5.tar.gz (86.4 kB view details)

Uploaded Source

Built Distribution

fastapi_key_auth-0.15.5-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_key_auth-0.15.5.tar.gz.

File metadata

  • Download URL: fastapi_key_auth-0.15.5.tar.gz
  • Upload date:
  • Size: 86.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fastapi_key_auth-0.15.5.tar.gz
Algorithm Hash digest
SHA256 f84d0e65b8399747241d506a36e06a64cc90a9f483556f48e4a80cbe2ec9e973
MD5 9b2c544f421208dc5ad2fd2dc4603fb7
BLAKE2b-256 bb8ba300842501693d64647676ee6f6599f7869292cce94ea985a995be867bbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_key_auth-0.15.5.tar.gz:

Publisher: main.yml on iwpnd/fastapi-key-auth

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_key_auth-0.15.5-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_key_auth-0.15.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a761917de22f8befe8a311163f3e8370325bb4e9d082e1bda4a7e485d19dd200
MD5 0b877305e33f876c3415e3fa73e57102
BLAKE2b-256 42122bb6e2151a2d052c70f8d376682f6a60ba9e1535f7cb329389d5ab25eb93

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_key_auth-0.15.5-py3-none-any.whl:

Publisher: main.yml on iwpnd/fastapi-key-auth

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 Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page