I
I
Ivan Vorobei2016-05-10 14:04:06
RESTful API
Ivan Vorobei, 2016-05-10 14:04:06

Authentication in Lumen: Middleware vs Provider?

For authentication, the Lumen documentation suggests using a Provider. At the same time, Middleware is also used.
In the Provider, you need to implement getting the user from the database, and in the Middleware, just check the user and make a response if the user is not found.
Why not combine work in Middleware ?
What practical purpose does a Service Provider serve ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2016-05-10
@ivanvorobei

Why not combine work in Middleware?

Service Provider and Middleware are responsible for different things. And one does not replace the other.
Sharing of responsibility.
The Service Provider can only do what is required of it. It has all the logic of work.
The middleware contains the logic to work with the request, it does not know HOW to authorize the user. It knows to pull AuthServiceProvider::guest(), for example, and depending on the result, skip the request further or abort it.
For simple applications, this is not critical, you can make at least one GodObject for everything, and it will work.
I need an idea in terms of expanding the functionality.

N
Nick Murzin, 2016-05-10
@R0s0maxa

Because it's called HTTP Middleware . Those. midlaveyr knows nothing about your database, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question