If you would like to assign middleware to specific route, you should define it under the middleware scope of your route definition.
extension_controller-action: ... options: middleware: - LMS\Routes\Middleware\Api\Authenticate
You may also assign multiple middleware to the route.
Just append as many as you need under the middleware.
extension_controller-action: ... options: middleware: - LMS\Routes\Middleware\Api\Authenticate - LMS\Routes\Middleware\Api\VerifyCsrfToken
Sometimes you may want to group several middleware under a single key to make them easier to assign to routes.
Out of the box, EXT:routes comes with
auth middleware group that contains common middleware you may want to apply to your web UI and API routes:
extension_controller-action: ... options: middleware: - auth
auth group just combines (Authenticate and VerifyCsrfToken) middleware, nothing more.
You also can create your own custom combinations if needed.
Combine Groups And Middleware¶
It’s logical, but we should mention that combination of groups and middleware is possible as well.
extension_controller-action: ... options: middleware: - auth - Vendor\Extension\Middleware\Api\MyCustomMiddleware - LMS\Routes\Middleware\Api\VerifyAdminBackendSession