From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Wed, 13 Jul 2022 04:29:57 +0000 (-0500) Subject: remove reference to add_middleware (#1763) X-Git-Tag: 0.21.0~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=55ab0b75f2c2897d627711391754fd631ac32427;p=thirdparty%2Fstarlette.git remove reference to add_middleware (#1763) --- diff --git a/docs/authentication.md b/docs/authentication.md index 513db5c8..6fe71d4e 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -178,6 +178,8 @@ You can customise the error response sent when a `AuthenticationError` is raised by an auth backend: ```python +from starlette.applications import Starlette +from starlette.middleware import Middleware from starlette.middleware.authentication import AuthenticationMiddleware from starlette.requests import Request from starlette.responses import JSONResponse @@ -186,5 +188,9 @@ from starlette.responses import JSONResponse def on_auth_error(request: Request, exc: Exception): return JSONResponse({"error": str(exc)}, status_code=401) -app.add_middleware(AuthenticationMiddleware, backend=BasicAuthBackend(), on_error=on_auth_error) +app = Starlette( + middleware=[ + Middleware(AuthenticationMiddleware, backend=BasicAuthBackend(), on_error=on_auth_error), + ], +) ```