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
    poetry install
    
  2. Install with pip
    pip install fastapi-key-auth
    
  3. Install with poetry
    poetry add fastapi-key-auth
    

Usage

As Middleware:

from fastapi import FastAPI
from fastapi_key_auth import AuthorizerMiddleware

app = FastAPI()

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

# optional use regex startswith
app.add_middleware(AuthorizerMiddleware, public_path=["/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.7.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

fastapi_key_auth-0.7.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-key-auth-0.7.1.tar.gz.

File metadata

  • Download URL: fastapi-key-auth-0.7.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for fastapi-key-auth-0.7.1.tar.gz
Algorithm Hash digest
SHA256 22bbf8bcf3fbc8a86bcdc29f236ff59e4e3e9a36c7f9d57cc7e5910eec8bdb86
MD5 2192daa8172ff49efd50a5c3dcf67ef3
BLAKE2b-256 56bdc567c2410208db70fe3327e8b4fa16d7a9b24570ad27073b1002746d88a3

See more details on using hashes here.

File details

Details for the file fastapi_key_auth-0.7.1-py3-none-any.whl.

File metadata

  • Download URL: fastapi_key_auth-0.7.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.2.0 pkginfo/1.7.1 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2

File hashes

Hashes for fastapi_key_auth-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dfc3ff4faac83f2c68a732c9dbf22c387507f16e0323d0303f6d8ced457d97fd
MD5 4dc7435c1f15fb3388e8c3303f8d300e
BLAKE2b-256 54be3ddd900360c7e6a61927969cbfc7e6b4d0e5b7533530b032fcb1a8195a4b

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