Skip to content

feat: support combining multiple security schemes #22

@adriangb

Description

@adriangb

See https://swagger.io/docs/specification/authentication/

Currently we only support OR for security models: if you specify multiple security models, if any of them passes auth passes.
OpenAPI supports combing OR and AND.
Technically you can achieve this by setting auto_error=False, but this isn't reflected in OpenAPI.

A better approach would be something like:

from dataclasses import data class

from xpresso import AnyOfSecurity

@dataclass
class SecurityModels:
    key1: Annotated[str, Security(...)]
    key2: Annotated[str, Security(...)]

async def endpoint(security: AnyOfSecurity[SecurityModels]) -> None:
    ...

AnyOfSecurity would just be Dependent subclass, with no effect on runtime, but that we can use when generating OpenAPI docs.
This has a nice parallel with how we handle forms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions