I’m developing a middleware for a system I’m trying to put to run.
As I am still starting in Zend Expressive, this week I had a difficulty in the authentication part, I could not find anything documented regarding my question and I went to Slack of the project, where I was helped by one of the colleagues that indicated an example of configuration file no git.
As I did not find any answer I decided to post here a workaround of how I solved the difficulty.
First of all, I will present the authentication workflow.
The OAuth2 server worked correctly, too.
The problem was when I inserted the pipe for the authentication, which caused Expressive to request a token even when I made the request requesting the token.
So the way I solved the problem was:
Before the pipe that calls RouteMiddleware, I include the following pipe:
$app-> pipe (’/auth’, Zend\Expressive\Authentication\OAuth2\OAuth2Middleware::class);
So instead of creating this route in my routes.php I created only this pipe that runs only for this route, and the other routes are treated conventionally with their respective middlewares.
I hope it helps someone else who has the same problem as me.