How to add multiple auth middlewares? #1987
-
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
It's going to have to be the latter since middlewares are designed to be completely independent from each other. We do not have anything about a case like this in the docs, but I think it might be a good addition to a recipes section. @litestar-org/maintainers? |
Beta Was this translation helpful? Give feedback.
-
Thank you, and for the lightning fast response. I'm happy to help contribute a generic recipe if I can get a pointer on how to programmatically call the middlewares. |
Beta Was this translation helpful? Give feedback.
-
Middlewares already call other middlewares / ASGI apps, since they themselves are ASGI apps as well. It usually looks something like await self.app(scope, send, receive) So if you were to wrap one middleware into another, you'd simply wrap these calls. You can take a look at https://github.com/litestar-org/litestar/blob/a288fd49ec50426da146f8e9071163d5b892c335/litestar/middleware/base.py or the middlewares in https://github.com/litestar-org/litestar/tree/a288fd49ec50426da146f8e9071163d5b892c335/litestar/middleware to see how that's usually implemented. |
Beta Was this translation helpful? Give feedback.
-
Thank you - just to update we are likely to try this soon, so we'll report back on our progress! |
Beta Was this translation helpful? Give feedback.
Middlewares already call other middlewares / ASGI apps, since they themselves are ASGI apps as well.
It usually looks something like
So if you were to wrap one middleware into another, you'd simply wrap these calls.
You can take a look at https://github.com/litestar-org/litestar/blob/a288fd49ec50426da146f8e9071163d5b892c335/litestar/middleware/base.py or the middlewares in https://github.com/litestar-org/litestar/tree/a288fd49ec50426da146f8e9071163d5b892c335/litestar/middleware to see how that's usually implemented.