API key validation Middleware
Project description
FastAPI-key-auth
Secure your FastAPI endpoints using API keys.
Report Bug
·
Request Feature
Table of Contents
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
- Clone and install
git clone https://github.com/iwpnd/fastapi-key-auth.git poetry install
- Install with pip
pip install fastapi-key-auth
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fastapi_key_auth-0.7.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2818f2771e4e815f16656f66463209e07c09746d31263b1fa7ebd3989c34db3f |
|
MD5 | 9dab007ba8b30c68c581ff64e479cd31 |
|
BLAKE2b-256 | ac5500ae3f270de6387a76134a6246e3af8f4db67b484b2b26902035316bf5a1 |