From 0b279b7fb6851be4fbec37663382da08c5030d10 Mon Sep 17 00:00:00 2001 From: Martin Parrish Date: Sun, 24 Sep 2017 01:28:54 +0100 Subject: [PATCH 1/4] Update Lumen Passport routes for 5.5 --- src/LumenPassport.php | 11 ++++++----- src/RouteRegistrar.php | 40 ++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/LumenPassport.php b/src/LumenPassport.php index 996d6e0..e80b282 100644 --- a/src/LumenPassport.php +++ b/src/LumenPassport.php @@ -64,10 +64,12 @@ public static function tokensExpireIn(DateTimeInterface $date = null, $clientId /** * Get a Passport route registrar. * - * @param array $options + * @param \Laravel\Lumen\Routing\Router $router + * @param callable|null $callback + * @param array $options * @return RouteRegistrar */ - public static function routes($callback = null, array $options = []) + public static function routes($router, $callback = null, array $options = []) { $callback = $callback ?: function ($router) { $router->all(); @@ -80,9 +82,8 @@ public static function routes($callback = null, array $options = []) $options = array_merge($defaultOptions, $options); - $callback->group($options, function ($router) use ($callback) { - $routes = new RouteRegistrar($router); - $routes->all(); + $router->group($options, function ($router) use ($callback) { + $callback(new RouteRegistrar($router)); }); } } diff --git a/src/RouteRegistrar.php b/src/RouteRegistrar.php index 8b61cf3..41a9f0c 100644 --- a/src/RouteRegistrar.php +++ b/src/RouteRegistrar.php @@ -5,19 +5,19 @@ class RouteRegistrar { /** - * Application + * \Laravel\Lumen\Routing\Router Router */ - private $app; + private $router; /** * Create a new route registrar instance. * - * @param $app + * @param \Laravel\Lumen\Routing\Router $router * @return void */ - public function __construct($app) + public function __construct(\Laravel\Lumen\Routing\Router $router) { - $this->app = $app; + $this->router = $router; } /** @@ -40,18 +40,18 @@ public function all() */ public function forAccessTokens() { - $this->app->post('/token', [ + $this->router->post('/token', [ 'uses' => 'AccessTokenController@issueToken', 'namespace' => '\Dusterio\LumenPassport\Http\Controllers' ]); - $this->app->group(['middleware' => ['auth']], function () { - $this->app->get('/tokens', [ + $this->router->group(['middleware' => ['auth']], function () { + $this->router->get('/tokens', [ 'uses' => 'AuthorizedAccessTokenController@forUser', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->delete('/tokens/{token_id}', [ + $this->router->delete('/tokens/{token_id}', [ 'uses' => 'AuthorizedAccessTokenController@destroy', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); @@ -65,7 +65,7 @@ public function forAccessTokens() */ public function forTransientTokens() { - $this->app->post('/token/refresh', [ + $this->router->post('/token/refresh', [ 'middleware' => ['auth'], 'uses' => 'TransientTokenController@refresh', 'namespace' => '\Laravel\Passport\Http\Controllers' @@ -79,23 +79,23 @@ public function forTransientTokens() */ public function forClients() { - $this->app->group(['middleware' => ['auth']], function () { - $this->app->get('/clients', [ + $this->router->group(['middleware' => ['auth']], function () { + $this->router->get('/clients', [ 'uses' => 'ClientController@forUser', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->post('/clients', [ + $this->router->post('/clients', [ 'uses' => 'ClientController@store', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->put('/clients/{client_id}', [ + $this->router->put('/clients/{client_id}', [ 'uses' => 'ClientController@update', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->delete('/clients/{client_id}', [ + $this->router->delete('/clients/{client_id}', [ 'uses' => 'ClientController@destroy', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); @@ -109,23 +109,23 @@ public function forClients() */ public function forPersonalAccessTokens() { - $this->app->group(['middleware' => ['auth']], function () { - $this->app->get('/scopes', [ + $this->router->group(['middleware' => ['auth']], function () { + $this->router->get('/scopes', [ 'uses' => 'ScopeController@all', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->get('/personal-access-tokens', [ + $this->router->get('/personal-access-tokens', [ 'uses' => 'PersonalAccessTokenController@forUser', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->post('/personal-access-tokens', [ + $this->router->post('/personal-access-tokens', [ 'uses' => 'PersonalAccessTokenController@store', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); - $this->app->delete('/personal-access-tokens/{token_id}', [ + $this->router->delete('/personal-access-tokens/{token_id}', [ 'uses' => 'PersonalAccessTokenController@destroy', 'namespace' => '\Laravel\Passport\Http\Controllers' ]); From eaeefd709bae0ddda4abab88391952be010d10d6 Mon Sep 17 00:00:00 2001 From: Martin Parrish Date: Sun, 24 Sep 2017 01:30:09 +0100 Subject: [PATCH 2/4] Update README for 5.5 router --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dc6563f..7c9439c 100644 --- a/README.md +++ b/README.md @@ -124,13 +124,13 @@ return [ Next, you should call the LumenPassport::routes method within the boot method of your application. This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens: ```php -Dusterio\LumenPassport\LumenPassport::routes($app); +Dusterio\LumenPassport\LumenPassport::routes($app->router); ``` You can add that into an existing group, or add use this route registrar independently like so; ```php -Dusterio\LumenPassport\LumenPassport::routes($app, ['prefix' => 'v1/oauth']); +Dusterio\LumenPassport\LumenPassport::routes($app->router, null, ['prefix' => 'v1/oauth']); ``` ## User model From 13ac7726f78c03d3d3bc270a9023eba7025fcc07 Mon Sep 17 00:00:00 2001 From: Martin Parrish Date: Sun, 24 Sep 2017 01:43:27 +0100 Subject: [PATCH 3/4] Update Lumen version dependency in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c9439c..a291ae8 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A simple service provider that makes Laravel Passport work with Lumen ## Dependencies * PHP >= 5.6.3 -* Lumen >= 5.3 +* Lumen >= 5.5 ## Installation via Composer From 8dcf118968f447efb5bd7571a50ccc2d95d020bb Mon Sep 17 00:00:00 2001 From: Martin Parrish Date: Wed, 27 Sep 2017 14:16:27 +0100 Subject: [PATCH 4/4] Use Route facade instead of having to pass the router object --- README.md | 4 ++-- src/LumenPassport.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a291ae8..a37eb8d 100644 --- a/README.md +++ b/README.md @@ -124,13 +124,13 @@ return [ Next, you should call the LumenPassport::routes method within the boot method of your application. This method will register the routes necessary to issue access tokens and revoke access tokens, clients, and personal access tokens: ```php -Dusterio\LumenPassport\LumenPassport::routes($app->router); +Dusterio\LumenPassport\LumenPassport::routes(); ``` You can add that into an existing group, or add use this route registrar independently like so; ```php -Dusterio\LumenPassport\LumenPassport::routes($app->router, null, ['prefix' => 'v1/oauth']); +Dusterio\LumenPassport\LumenPassport::routes(null, ['prefix' => 'v1/oauth']); ``` ## User model diff --git a/src/LumenPassport.php b/src/LumenPassport.php index e80b282..b9f480e 100644 --- a/src/LumenPassport.php +++ b/src/LumenPassport.php @@ -6,6 +6,7 @@ use DateTimeInterface; use DateInterval; use Carbon\Carbon; +use Illuminate\Support\Facades\Route; class LumenPassport { @@ -64,12 +65,11 @@ public static function tokensExpireIn(DateTimeInterface $date = null, $clientId /** * Get a Passport route registrar. * - * @param \Laravel\Lumen\Routing\Router $router * @param callable|null $callback * @param array $options * @return RouteRegistrar */ - public static function routes($router, $callback = null, array $options = []) + public static function routes($callback = null, array $options = []) { $callback = $callback ?: function ($router) { $router->all(); @@ -82,7 +82,7 @@ public static function routes($router, $callback = null, array $options = []) $options = array_merge($defaultOptions, $options); - $router->group($options, function ($router) use ($callback) { + Route::group($options, function ($router) use ($callback) { $callback(new RouteRegistrar($router)); }); }