-
First check
ExampleHere's a self-contained minimal, reproducible, example with my use case: from fastapi import Depends
from fastapi.security.api_key import APIKeyBase
from fastapi.openapi.models import APIKey, APIKeyIn
class HMACModel(BaseModel):
api_key: APIKey = APIKey(**{"in": APIKeyIn.header}, name='Api-Key')
signature: APIKey = APIKey(**{"in": APIKeyIn.header}, name='Signature')
class HMACAuth(APIKeyBase):
model = HMACModel()
scheme_name = 'HMACAuth'
async def __call__(self, request: Request):
api_key = request.headers.get('Api-Key')
signature = request.headers.get('Signature')
print('check signature...')
return api_key
@app.get('/')
async def test(auth=Depends(HMACAuth())):
return ''DescriptionI define a custom
The solution you would likeSupport custom security schema or give some way to solve it. Environment
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
I find that it may be a flaw of OpenAPI. related issue: |
Beta Was this translation helpful? Give feedback.
I find that it may be a flaw of OpenAPI.
Custom security types are not supported in OpenAPI, too. The solution of "mutiple api keys" in OpenAPI is define mutiple "ApiKeys" security sheme, and make them work together in path operation's security. It's weird and hard to describe in ONE security model of FastAPI.
related issue:
OpenAPI-Specification/issues/2292
swagger-api/swagger-ui#3521