Skip to content

Commit f21e9d6

Browse files
committed
Update router configuration
1 parent 74d1664 commit f21e9d6

File tree

7 files changed

+56
-26
lines changed

7 files changed

+56
-26
lines changed

src/Configuration.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ final class Configuration implements ConfigurationContract
5353
self::CONFIG_BACKCHANNEL_LOGOUT_EXPIRES,
5454
];
5555

56-
/**
57-
* @var string
58-
*/
59-
public const CONFIG_NAMESPACE = 'auth0.';
60-
61-
/**
62-
* @var string
63-
*/
64-
public const CONFIG_NAMESPACE_ROUTES = 'auth0.routes.';
65-
6656
/**
6757
* @var string
6858
*/
@@ -158,6 +148,16 @@ final class Configuration implements ConfigurationContract
158148
*/
159149
public const CONFIG_MANAGEMENT_TOKEN_CACHE = 'managementTokenCache';
160150

151+
/**
152+
* @var string
153+
*/
154+
public const CONFIG_NAMESPACE = 'auth0.';
155+
156+
/**
157+
* @var string
158+
*/
159+
public const CONFIG_NAMESPACE_ROUTES = 'auth0.routes.';
160+
161161
/**
162162
* @var string
163163
*/
@@ -480,6 +480,17 @@ public static function getPath(): string
480480
return self::$path;
481481
}
482482

483+
public static function string(string $key, ?string $default = null): ?string
484+
{
485+
$value = config($key, $default);
486+
487+
if (is_string($value)) {
488+
return $value;
489+
}
490+
491+
return null;
492+
}
493+
483494
public static function stringOrIntToIntOrNull(
484495
int | string $value,
485496
int | null $default = null,

src/Controllers/CallbackControllerAbstract.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
namespace Auth0\Laravel\Controllers;
66

77
use Auth0\Laravel\Auth\Guard;
8-
use Auth0\Laravel\Configuration;
98
use Auth0\Laravel\Entities\CredentialEntityContract;
10-
use Auth0\Laravel\Events;
119
use Auth0\Laravel\Events\{AuthenticationFailed, AuthenticationSucceeded};
1210
use Auth0\Laravel\Exceptions\ControllerException;
1311
use Auth0\Laravel\Exceptions\Controllers\CallbackControllerException;
1412
use Auth0\Laravel\Guards\GuardAbstract;
13+
use Auth0\Laravel\{Configuration, Events};
1514
use Illuminate\Auth\Events\{Attempting, Authenticated, Failed, Validated};
1615
use Illuminate\Contracts\Auth\Authenticatable;
1716
use Illuminate\Http\Request;

src/Controllers/LoginControllerAbstract.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
namespace Auth0\Laravel\Controllers;
66

77
use Auth0\Laravel\Auth\Guard;
8-
use Auth0\Laravel\Configuration;
98
use Auth0\Laravel\Entities\CredentialEntityContract;
10-
use Auth0\Laravel\Events;
119
use Auth0\Laravel\Events\LoginAttempting;
1210
use Auth0\Laravel\Exceptions\ControllerException;
1311
use Auth0\Laravel\Guards\GuardAbstract;
12+
use Auth0\Laravel\{Configuration, Events};
1413
use Illuminate\Http\Request;
1514
use Symfony\Component\HttpFoundation\Response;
1615

@@ -42,11 +41,13 @@ public function __invoke(
4241

4342
if ($loggedIn) {
4443
return redirect()->intended(
45-
config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_AFTER_LOGIN,
46-
config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_INDEX,
47-
'/'
48-
)
49-
)
44+
config(
45+
Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_AFTER_LOGIN,
46+
config(
47+
Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_INDEX,
48+
'/',
49+
),
50+
),
5051
);
5152
}
5253

src/Controllers/LogoutControllerAbstract.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public function __invoke(
3737

3838
$loggedIn = $guard->check() ? true : null;
3939
$loggedIn ??= (($guard instanceof Guard) ? $guard->find(Guard::SOURCE_SESSION) : $guard->find()) instanceof CredentialEntityContract;
40-
$landing = config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_AFTER_LOGOUT, config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_INDEX, '/'));
40+
41+
$landing = Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_AFTER_LOGOUT);
42+
$landing ??= Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_INDEX);
43+
$landing ??= '/';
4144

4245
if ($loggedIn) {
4346
session()->invalidate();

src/ServiceAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ final public static function routes(
5555
string $authenticationGuard = 'auth0-session',
5656
): void {
5757
Route::group(['middleware' => ['web', 'guard:' . $authenticationGuard]], static function (): void {
58-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGIN, '/login'), LoginController::class)->name('login');
59-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGOUT, '/logout'), LogoutController::class)->name('logout');
60-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_CALLBACK, '/callback'), CallbackController::class)->name('callback');
58+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGIN) ?? '/login', LoginController::class)->name('login');
59+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGOUT) ?? '/logout', LogoutController::class)->name('logout');
60+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_CALLBACK) ?? '/callback', CallbackController::class)->name('callback');
6161
});
6262
}
6363
}

src/ServiceProviderAbstract.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ final public function registerRoutes(): void
220220
{
221221
if (true === config('auth0.registerAuthenticationRoutes')) {
222222
Route::group(['middleware' => 'web'], static function (): void {
223-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGIN, '/login'), LoginController::class)->name('login');
224-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGOUT, '/logout'), LogoutController::class)->name('logout');
225-
Route::get(config(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_CALLBACK, '/callback'), CallbackController::class)->name('callback');
223+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGIN) ?? '/login', LoginController::class)->name('login');
224+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_LOGOUT) ?? '/logout', LogoutController::class)->name('logout');
225+
Route::get(Configuration::string(Configuration::CONFIG_NAMESPACE_ROUTES . Configuration::CONFIG_ROUTE_CALLBACK) ?? '/callback', CallbackController::class)->name('callback');
226226
});
227227
}
228228
}

tests/Unit/ConfigurationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,19 @@
148148
->toBeInt()
149149
->toEqual(123);
150150
});
151+
152+
test('string() behaves as expected', function (): void {
153+
config(['test2' => [
154+
'testInteger' => 123,
155+
'testString' => '123',
156+
]]);
157+
158+
define('AUTH0_OVERRIDE_CONFIGURATION_STRING_METHOD', 'test2');
159+
160+
expect(Configuration::string('test2.testInteger'))
161+
->toBeNull();
162+
163+
expect(Configuration::string('test2.testString'))
164+
->toBeString()
165+
->toEqual('123');
166+
});

0 commit comments

Comments
 (0)