Skip to content
Discussion options

You must be logged in to vote

Litestar doesn't ship a Basic Auth scheme out of the box, but the building blocks are there. Subclass AbstractAuthenticationMiddleware and add a SecurityScheme entry in the OpenAPI config for the doc side.

Sketch:

import base64
from litestar import Litestar
from litestar.connection import ASGIConnection
from litestar.exceptions import NotAuthorizedException
from litestar.middleware import AbstractAuthenticationMiddleware, AuthenticationResult
from litestar.openapi.config import OpenAPIConfig
from litestar.openapi.spec import Components, SecurityScheme


class BasicAuthMiddleware(AbstractAuthenticationMiddleware):
    async def authenticate_request(self, connection: ASGIConnection) -> Auth…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JCHacking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants