Comments (19)
I have it working with:
Lumen 5.5
LumenPassport 0.2.0
Dusterio\LumenPassport\LumenPassport::routes( $app->router);
or
Dusterio\LumenPassport\LumenPassport::routes( $this->app->router);
or
Dusterio\LumenPassport\LumenPassport::routes( app()->router);
The implementation is dependent on placement.
from lumen-passport.
@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 $router
replaced $app
in 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(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
// $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->register( $LaravelPassportClass );
$app->register( $LumenPassportClass );
// register routes
Dusterio\LumenPassport\LumenPassport::routes( $app, ['prefix' => 'api/v1/oauth'] );//, 'middleware' => 'reject'
}
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});
return $app;
from lumen-passport.
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 ^_^
from lumen-passport.
@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 😉
from lumen-passport.
Can confirm that the solution provided by @ronnie-depp works perfectly on a fresh install of Lumen 5.5 and LumenPassport 0.2.0 👍
from lumen-passport.
I currently have the following inside my bootstrap/app.php file:
/ 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->register( $LaravelPassportClass );
$app->register( $LumenPassportClass );
// register routes
\Dusterio\LumenPassport\LumenPassport::routes( $app );
}else .... // I have custom Logging and Response handlers here
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).
from lumen-passport.
Had a similar problem, had to edit the vendor folders but this seemed to fix it:
vendor/dusterio/lumen-passport/src/LumenPassport.php
Then edit line 83 from
$callback->group(...
to
$callback->router->group(...
from lumen-passport.
The last version auto-detects version, you can pass app() or router - it will work either way
from lumen-passport.
@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.
from lumen-passport.
You can call this method from any service provider of your choice?
The exception you are getting says you haven't registered the routes
from lumen-passport.
@dusterio @freddieRv @DCdeBrabander @andrew-s @jmarcher please help me i have the same issue.
i get the following error when i use code:
// register routes
\Dusterio\LumenPassport\LumenPassport::routes( $app );
by @DCdeBrabander he posted above:
(1/1) FatalThrowableError
Call to undefined method Laravel\Lumen\Application::group()
--
in LumenPassport.php (line 83)
at LumenPassport::routes(object(Application))in app.php (line 98)
at require('D:\xampp-7.1.7-vc14\htdocs\RestApi\bootstrap\app.php')in index.php (line 14)
if i don't pass $app
, it says:
Call to undefined method Closure::group()
so either way i'm failing for 7+hours now.
PLEASE HELP
from lumen-passport.
@ronnie-depp
Did you install the package via composer require
and dump-autoload
already?
Did you enable facades and eloquent?
// Enable Facades
$app->withFacades();
// Enable Eloquent
$app->withEloquent();
This is also mentioned in the readme: https://github.com/dusterio/lumen-passport
Please let me know what you did before try using the code
from lumen-passport.
yes i used composer require dusterio/lumen-passport
here is my lumen 5.5 bootstrap/app.php
`<?php
require_once DIR.'/../vendor/autoload.php';
try {
(new Dotenv\Dotenv(DIR.'/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
//
}
/* |
---|
Create The Application |
-------------------------------------------------------------------------- |
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
realpath(DIR.'/../')
);
$app->withFacades();
$app->withEloquent();
/* |
---|
Register Container Bindings |
-------------------------------------------------------------------------- |
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
/* |
---|
Register Middleware |
-------------------------------------------------------------------------- |
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
// $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class
// ]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
/* |
---|
Register Service Providers |
-------------------------------------------------------------------------- |
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
// $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->register( $LaravelPassportClass );
$app->register( $LumenPassportClass );
// register routes
Dusterio\LumenPassport\LumenPassport::routes( $app, ['prefix' => 'api/v1/oauth', 'middleware' => 'reject' ] );
}
/* |
---|
Load The Application Routes |
-------------------------------------------------------------------------- |
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require DIR.'/../routes/web.php';
});
return $app;
`
please check the code thoroughly.
i'm stuck with this with no where to go. unable to get the /oauth/token or other routes that should have been generated automatically.
from lumen-passport.
I'm having the same issue. I have tried Lumen 5.4 & 5.5.
@DCdeBrabander I was unable to Register the Routes as you pointed out. Because when I pass $app to:
Dusterio\LumenPassport\LumenPassport::routes($app);
it gives me error saying $app is undefined. And when I replace $app with app()
Dusterio\LumenPassport\LumenPassport::routes(app());
it says that group method is undefined in Dusterio\LumenPassport\LumenPassport::routes line#83 as $callback->group is replaced by Laravel\Lumen\Application->group()
@DCdeBrabander how to get the Application-Root? Please point out.
PLEASE HELP @dusterio
from lumen-passport.
@ronnie-depp Can you please format your codeblock with 'insert code' in this editor or with 3 (or 4?) backticks? :-P It currently is very hard to read.
I currently have Lumen 5.3.3. and 5.4.7 working with LumenPassport (versions 0.1.9 and 0.2.0), at least as far as registering routes goes. Assuming that you followed the readme completely, my guess is that is probably has something to with different versions of the used Laravel's Passport? My newest working version of LumenPassport is installed with LaravelPassport v4.0.1. To check I simply used:
composer show | grep "passport"
@dusterio Have you looked into this? Can it be an update?
If it is, people should test the proposed fix (of @Arteyan ) .
edit
For me this is working code, note the absence of the other arguments inside the route() method:
// 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->register( $LaravelPassportClass );
$app->register( $LumenPassportClass );
// register routes
\Dusterio\LumenPassport\LumenPassport::routes( $app );
}
// Define expiry dates of tokens
\Laravel\Passport\Passport::tokensExpireIn(\Carbon\Carbon::now()->addSeconds( env('API_ACCESS_TOKEN_TTL', 600) ));
\Laravel\Passport\Passport::refreshTokensExpireIn(\Carbon\Carbon::now()->addDays( env('API_REFRESH_TOKEN_TTL', 600) ));
// Load config/oauth_clients and define the different user 'scopes'.
// @NOTE This is normally used for 'roles' instead of 'usertypes'
$app->configure( 'oauth_client' );
\Laravel\Passport\Passport::tokensCan( config('oauth_client.scopes') );
from lumen-passport.
@freddieRv please see above solution. this fixes the issue.
from lumen-passport.
I'm using Lumen 5.6, and registering it in the web.php file:
Dusterio \ LumenPassport \ LumenPassport :: routes ($ this-> app);
I get the error:
(1/1) FatalThrowableError
Using this when not in object context
I have already changed the package versions to "0.2.0" and "0.2.5" and still the error persists.
from lumen-passport.
@henriquesousa have you followed the above comments. That might help you solve your issue. I haven't yet checked or worked with Lumen 5.6, Latest versions of LumenPassport and LaravelPassport.
please check above conversation to get an idea what steps are necessary to follow to successfully implement what you came for.
Also it can be a new issue with latest versions and configuration options. In which case only author of LumenPassort or Some else who fixed similar issue may help you. Keep looking but with fresh mind.
Note these comments might be helpful:
from lumen-passport.
guys i have a doubt im new at this, how suppose to be my serviceprovider, to make this part, i dont have any idea
from lumen-passport.
Related Issues (20)
- Refresh Token HOT 1
- token expire at now work HOT 1
- Unable to resolve dependency [Parameter #1 [ <required> $tokenId ]] in class Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController HOT 4
- Error 400, error": "invalid_grant" HOT 7
- NotFoundHttpException HOT 5
- PHP 8 Support
- It's not working with mongodb
- Is this repository dead?
- php artisan passport:install error. HOT 1
- Lumen passport custom data in payload HOT 5
- Using Multiple Authentication
- How to load the passport keys from different folder ?
- create client password grant each user
- getting error on install passport in lumen 9 HOT 2
- not support lumen 9 HOT 12
- getting error on install passport in lumen 9 HOT 22
- Restrictions with models
- Error with Lumen 10x HOT 15
- Call to undefined method Laravel\Lumen\Routing\Router::middleware() HOT 3
- Getting error on installation for Lumen 10.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lumen-passport.