lumen-passport: OAuth routes not working
Working with Lumen 5.4, fresh install. I followed all the steps until this part:
‘Next, you should call the LumenPassport::routes method within the boot method of your application.’
I don’t understand where I have to call this method, and the oauth routes are not working. I get a ‘NotFoundHttpException’ exception.
I found this tutorial and there’s no mention of this step, I also noticed that the version used is 0.1 and the latest one is 0.2. So I guess you changed something that makes this extra step needed.
What I mean to say is that the documentation should be more specific for those of us who are not that familiar with laravel/lumen.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (2 by maintainers)
I have it working with:
Lumen 5.5 LumenPassport 0.2.0
Dusterio\LumenPassport\LumenPassport::routes( $app->router);orDusterio\LumenPassport\LumenPassport::routes( $this->app->router);orDusterio\LumenPassport\LumenPassport::routes( app()->router);The implementation is dependent on placement.
now, lumen 5.5 uses var $route for defining route, not $app which was used at lumen 5.4. I was aware of this difference, but didn’t figured out on configuring dusterio-lumenpassport. You have save my time. It’s worked. Thanks a lot ^_^
@dusterio , @DCdeBrabander , my Lumen version is 5.5 & LumenPassport ver 0.2.0 @freddieRv please use a fresh install of Lumen 5.5 and LumenPassport 0.2.0 and follow along. This solution works.
You were right @Arteyan in Lumen 5.5 i already noticed
$routerreplaced$appin routes\web.php I changed line#83 in vendor\dusterio\lumen-passport\src\LumenPassport.php, from:$callback->group($options, function ($router) use ($callback) {to this:$callback->router->group($options, function ($router) use ($callback) {and voila! it fixed the problem. I think @dusterio should consider updating the code and pushing a new version.
I thank you @Arteyan and @DCdeBrabander for your contributing replies to help me out. Thanks again guys.
@DCdeBrabander here is my code in \bootstrap\app.php
require_once __DIR__.'/../vendor/autoload.php';try { (new Dotenv\Dotenv(__DIR__.'/../'))->load(); } catch (Dotenv\Exception\InvalidPathException $e) { // }$app = new Laravel\Lumen\Application( realpath(__DIR__.'/../') );$app->withFacades();$app->withEloquent();$app->singleton();$app->singleton();// $app->middleware([ // App\Http\Middleware\ExampleMiddleware::class // ]);$app->routeMiddleware([ 'auth' => App\Http\Middleware\Authenticate::class, ]);// $app->register(App\Providers\AppServiceProvider::class);// $app->register(App\Providers\AuthServiceProvider::class);// $app->register(App\Providers\EventServiceProvider::class);$app->register(App\Providers\RepositoriesServiceProvider::class);//$app->register(Laravel\Passport\PassportServiceProvider::class);//$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);$app->register(App\Providers\AuthServiceProvider::class);// Register two Passport service providers - original one and Lumen adapter// @NOTE https://github.com/dusterio/lumen-passport$LaravelPassportClass = Laravel\Passport\PassportServiceProvider::class;$LumenPassportClass = Dusterio\LumenPassport\PassportServiceProvider::class;if( class_exists( $LaravelPassportClass ) && class_exists( $LumenPassportClass ) ){}$app->router->group([], function ($router) {});return $app;Can confirm that the solution provided by @ronnie-depp works perfectly on a fresh install of Lumen 5.5 and LumenPassport 0.2.0 👍
@ronnie-depp I’m glad I could help 👍 But I still suggest you format your codeblock correctly. It’s better but still a bit weird to read. Dot this not for me, but for the people looking for solutions in the future 😉
@upwebdesign will try your solution. It seems to be the proper way without modifying /vendor/ directory and files in it.
But will also have to try the latest versions as @dusterio say that it auto-detects the version and that app or router, any can be passed and will work.
The last version auto-detects version, you can pass app() or router - it will work either way
Had a similar problem, had to edit the vendor folders but this seemed to fix it:
vendor/dusterio/lumen-passport/src/LumenPassport.phpThen edit line 83 from
$callback->group(...to$callback->router->group(...I currently have the following inside my bootstrap/app.php file:
But basically what @dusterio already said, doesn’t matter that much where you put it but there are some best practices (such as service providers).