Bot releases are visible (Hide)
Published by iwpnd over 3 years ago
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)])
Published by iwpnd over 3 years ago
public_path
from fastapi Import FastAPI
from fastapi_key_path import AuthorizerMiddleware
app = FastAPI()
app.add_middleware(AuthorizerMiddleware, public_paths=["/ping", "^/public"])
Published by iwpnd over 3 years ago
public_paths
validationPublished by iwpnd over 3 years ago
exclude path from x-api-key
requirement.
from fastapi import FastAPI
from fastap_key_auth import AuthorizerMiddleware
app = FastAPI()
app.add_middleware(AuthorizerMiddleware, public_paths=["/health"])
Published by iwpnd over 3 years ago
Secure your FastAPI with a middleware validating x-api-key
in the header of incoming requests. Is the x-api-key
present in your applications environment they will be authorized, else not. 🤩
Example:
from fastapi import FastAPI
from fastapi_key_auth import AuthorizerMiddleware
app = FastAPI()
app.add_middleware(AuthorizerMiddleware)