Lumen-framework: Lumen guards broken in AuthServiceProvider

Created on 20 Jun 2017  路  12Comments  路  Source: laravel/lumen-framework

  • Lumen Version: 5.4.6
  • PHP Version: 7.1
  • Database Driver & Version: Mysql

Description:

Can't capture the request in the boot function of AuthServiceProvider class, actually this is happen with the last fix on the container bound position https://github.com/laravel/framework/commit/778b1ff0d7d3227f178344a6621edbd999770b4d

In laravel, the request is instantiate from the beginning and when this pass for the instance method of the container class the object is updated but in lumen this don't happen cuz when we call to the refresh method of the container the request object never was instantiated before and with this in the AuthProviderService we get a empty Request object.

Steps To Reproduce:

  • This is easy get a clean installation of Lumen 5.4.6
  • Uncomment AuthServiceProvider in bootstrap/app.php
  • Go to app/Providers/AuthServiceProvider.php and dump the Request object inside of the closure in viaRequest call
  • After that make a http request to ur installation and pass any header

PD: this is bad cuz i have a system with JWT authentication and i can't validate any user of my system cuz i can't capture the token in the header of the request.

All 12 comments

@Azakur4 you should use a middleware for that....don't use request class in your service provider

actually i don't create a Request object in the AuthServiceProvider, i follow the example of the lumen boilerplate that he use the request objecte inside the closure of viaRequest method see this:

https://github.com/laravel/lumen/blob/master/app/Providers/AuthServiceProvider.php#L26-L39

that request object always be empty in lumen, with the last fix of Illuminate/Container

and what gives $request->headers->all();?

return and empty array []

@taylorotwell some help with this pls

@Azakur4 How did you manage to solve the issue?

i put this line in my composer.json

section require

"illuminate/container": "5.4.19"

in that version of the container all is working after that the problem appear.

I discovered that my issue was with an external package but thanks for the tip anyway!

@Azakur4

I had a similar problem , when my request was not yet binded. When do you register your code? In boot or in register method?

@catalinux in boot

I'm getting bit by this one as well - again trying to use JWT authentication following the basic use case from the docs.

Has anyone got a nice solution / example for how/where to handle the JWT headers now if the $request object can't be used in a service provider?

Everywhere says middleware should be used but I'm not seeing how I get from doing something in middle to being able to return the correct user from the AuthServiceProvider.

Update - actually looks like Sentry was the culprit for me (same as reported: https://stackoverflow.com/a/44658326)

Closing this issue because it's already solved, old or not relevant anymore. Feel free to reply if you're still experiencing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhengyuhe123 picture zhengyuhe123  路  4Comments

timrogers picture timrogers  路  3Comments

jairobjunior picture jairobjunior  路  4Comments

codercms picture codercms  路  4Comments

rmblstrp picture rmblstrp  路  5Comments