Skip to content

Commit

Permalink
feat: add option to enable and disable login route (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricklambrechts authored Jun 27, 2023
1 parent 44e7078 commit 6ca3fbc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config/oidc.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,26 @@
* Route configuration
*/
'route_configuration' => [
/**
* Enable or disable the login route.
*/
'enabled' => env('OIDC_LOGIN_ROUTE_ENABLED', true),

/**
* The url of the login route.
*/
'login_route' => env('OIDC_LOGIN_ROUTE', '/oidc/login'),

/**
* The middleware that runs on the login route.
*/
'middleware' => [
'web'
],

/**
* The prefix of the login route.
*/
'prefix' => '',
]
];
19 changes: 19 additions & 0 deletions src/OpenIDConnectServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function boot(): void

protected function registerRoutes(): void
{
if (!$this->routesEnabled()) {
return;
}

Route::group($this->routeConfiguration(), function () {
$this->loadRoutesFrom(__DIR__ . '/../routes/oidc.php');
});
Expand All @@ -60,6 +64,21 @@ protected function routeConfiguration(): array
];
}

/**
* Check in config if the routes are enabled.
*
* @return bool
*/
protected function routesEnabled(): bool
{
$enabled = config('oidc.route_configuration.enabled');
if (!is_bool($enabled)) {
return false;
}

return $enabled;
}

protected function registerConfigurationLoader(): void
{
$this->app->singleton(OpenIDConfigurationLoader::class, function (Application $app) {
Expand Down

0 comments on commit 6ca3fbc

Please sign in to comment.