]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
remove reference to add_middleware (#1763)
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Wed, 13 Jul 2022 04:29:57 +0000 (23:29 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Jul 2022 04:29:57 +0000 (23:29 -0500)
docs/authentication.md

index 513db5c84808d826d20f1ec421fe86685657d938..6fe71d4e1ac7b53b40d2c017acefab567a10185c 100644 (file)
@@ -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),
+    ],
+)
 ```