Skip to content

Commit

Permalink
[11.x] Allow for bootstrapping without loading routes (#1564)
Browse files Browse the repository at this point in the history
* Allow for bootstrapping without loading routes

* Update Passport.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
axlon and taylorotwell authored Aug 29, 2022
1 parent 5629f1a commit e312f36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ class Passport
*/
public static $authorizationServerResponseType;

/**
* Indicates if Passport routes will be registered.
*
* @var bool
*/
public static $registersRoutes = true;

/**
* Enable the implicit grant type.
*
Expand Down Expand Up @@ -630,6 +637,18 @@ public static function tokenEncryptionKey(Encrypter $encrypter)
$encrypter->getKey();
}

/**
* Configure Passport to not register its routes.
*
* @return static
*/
public static function ignoreRoutes()
{
static::$registersRoutes = false;

return new static;
}

/**
* Configure Passport to not register its migrations.
*
Expand Down
16 changes: 9 additions & 7 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public function boot()
*/
protected function registerRoutes()
{
Route::group([
'as' => 'passport.',
'prefix' => config('passport.path', 'oauth'),
'namespace' => 'Laravel\Passport\Http\Controllers',
], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
});
if (Passport::$registersRoutes) {
Route::group([
'as' => 'passport.',
'prefix' => config('passport.path', 'oauth'),
'namespace' => 'Laravel\Passport\Http\Controllers',
], function () {
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
});
}
}

/**
Expand Down

0 comments on commit e312f36

Please sign in to comment.