Skip to content

Commit af2743f

Browse files
committed
Merge branch 'main' into feat/restore-configurable-route-paths
2 parents 5789f41 + a5d172a commit af2743f

File tree

7 files changed

+95
-16
lines changed

7 files changed

+95
-16
lines changed

composer.json

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"require": {
3838
"php": "^8.1",
3939
"ext-json": "*",
40-
"auth0/auth0-php": "^8.9",
40+
"auth0/auth0-php": "^8.10",
4141
"illuminate/contracts": "^9 || ^10",
4242
"illuminate/http": "^9 || ^10",
4343
"illuminate/support": "^9 || ^10",
@@ -56,7 +56,7 @@
5656
"phpstan/phpstan-strict-rules": "^1",
5757
"psalm/plugin-laravel": "^2",
5858
"psr-mock/http": "^1",
59-
"rector/rector": "0.17.6",
59+
"rector/rector": "0.17.0",
6060
"squizlabs/php_codesniffer": "^3",
6161
"symfony/cache": "^6",
6262
"vimeo/psalm": "^5",
@@ -112,20 +112,11 @@
112112
}
113113
},
114114
"scripts": {
115-
"pest": [
116-
"@putenv XDEBUG_MODE=coverage",
117-
"@php vendor/bin/pest --colors=always --strict-global-state --fail-on-risky --fail-on-warning --coverage --strict-coverage --compact"
118-
],
119-
"pest:ci": [
120-
"@pest:fast --order-by=random --no-progress"
121-
],
122-
"pest:fast": [
123-
"@pest --parallel"
124-
],
125-
"phpcs": [
126-
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
127-
"@php vendor/bin/php-cs-fixer fix --dry-run --diff"
128-
],
115+
"pest": "@php vendor/bin/pest --order-by random --fail-on-risky --parallel --no-progress",
116+
"pest:coverage": "@php vendor/bin/pest --order-by random --fail-on-risky --coverage --parallel --no-progress",
117+
"pest:debug": "@php vendor/bin/pest --log-events-verbose-text pest.log --display-errors --fail-on-risky --no-progress",
118+
"pest:profile": "@php vendor/bin/pest --profile",
119+
"phpcs": "@php vendor/bin/php-cs-fixer fix --dry-run --diff",
129120
"phpcs:fix": "@php vendor/bin/php-cs-fixer fix",
130121
"phpstan": "@php vendor/bin/phpstan analyze",
131122
"psalm": "@php vendor/bin/psalm",

config/auth0.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
Configuration::CONFIG_CLIENT_ASSERTION_SIGNING_KEY => Configuration::get(Configuration::CONFIG_CLIENT_ASSERTION_SIGNING_KEY),
3838
Configuration::CONFIG_CLIENT_ASSERTION_SIGNING_ALGORITHM => Configuration::get(Configuration::CONFIG_CLIENT_ASSERTION_SIGNING_ALGORITHM),
3939
Configuration::CONFIG_PUSHED_AUTHORIZATION_REQUEST => Configuration::get(Configuration::CONFIG_PUSHED_AUTHORIZATION_REQUEST),
40+
Configuration::CONFIG_BACKCHANNEL_LOGOUT_CACHE => Configuration::get(Configuration::CONFIG_BACKCHANNEL_LOGOUT_CACHE),
41+
Configuration::CONFIG_BACKCHANNEL_LOGOUT_EXPIRES => Configuration::get(Configuration::CONFIG_BACKCHANNEL_LOGOUT_EXPIRES),
4042
],
4143

4244
'api' => [

docs/BackchannelLogout.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Backchannel Logout
2+
3+
The Auth0 Laravel SDK supports [Backchannel Logout](https://auth0.com/docs/authenticate/login/logout/back-channel-logout) from v7.12 onward. To use this feature, some additional configuration is necessary:
4+
5+
1. **Add a new route to your application.** This route must be publicly accessible. Auth0 will use it to send backchannel logout requests to your application. For example:
6+
7+
```php
8+
Route::post('/backchannel', function (Request $request) {
9+
if ($request->has('logout_token')) {
10+
app('auth0')->handleBackchannelLogout($request->string('logout_token', '')->trim());
11+
}
12+
});
13+
```
14+
15+
2. **Configure your Auth0 tenant to use Backchannel Logout.** See the [Auth0 documentation](https://auth0.com/docs/authenticate/login/logout/back-channel-logout/configure-back-channel-logout) for more information on how to do this. Please ensure you point the Logout URI to the backchannel route we just added to your application.
16+
17+
Note: If your application's configuration assigns `false` to the `backchannelLogoutCache` SDK configuration property, this feature will be disabled entirely.

docs/Configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ The following environment variables are supported, but should not be adjusted un
8585
| `AUTH0_CLIENT_ASSERTION_SIGNING_KEY` | `String` The key to use for signing client assertions. |
8686
| `AUTH0_CLIENT_ASSERTION_SIGNING_ALGORITHM` | `String` The algorithm to use for signing client assertions. Defaults to `RS256`. |
8787
| `AUTH0_PUSHED_AUTHORIZATION_REQUEST` | `Boolean` Whether the SDK should use Pushed Authorization Requests during authentication. Note that your tenant must have this feature enabled. Defaults to `false`. |
88+
| `AUTH0_BACKCHANNEL_LOGOUT_CACHE` | `String (class name)` A PSR-6 class to use for caching backchannel logout tokens. |
89+
| `AUTH0_BACKCHANNEL_LOGOUT_EXPIRES` | `Integer` How long (in seconds) to cache a backchannel logout token. Defaults to `2592000` (30 days). |
8890

8991
### Order of Priority
9092

src/Configuration.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,24 @@ final class Configuration implements ConfigurationContract
5050
self::CONFIG_TOKEN_CACHE_TTL,
5151
self::CONFIG_HTTP_MAX_RETRIES,
5252
self::CONFIG_COOKIE_EXPIRES,
53+
self::CONFIG_BACKCHANNEL_LOGOUT_EXPIRES,
5354
];
5455

5556
/**
5657
* @var string
5758
*/
5859
public const CONFIG_AUDIENCE = 'audience';
5960

61+
/**
62+
* @var string
63+
*/
64+
public const CONFIG_BACKCHANNEL_LOGOUT_CACHE = 'backchannelLogoutCache';
65+
66+
/**
67+
* @var string
68+
*/
69+
public const CONFIG_BACKCHANNEL_LOGOUT_EXPIRES = 'backchannelLogoutExpires';
70+
6071
/**
6172
* @var string
6273
*/

src/Entities/InstanceEntityAbstract.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __construct(
2929
protected ?CacheItemPoolInterface $tokenCachePool = null,
3030
protected ?CacheItemPoolInterface $managementTokenCachePool = null,
3131
protected ?string $guardConfigurationKey = null,
32+
protected ?CacheItemPoolInterface $backchannelLogoutCachePool = null,
3233
) {
3334
}
3435

@@ -119,6 +120,29 @@ abstract public function setConfiguration(
119120
SdkConfiguration | array | null $configuration = null,
120121
): self;
121122

123+
protected function bootBackchannelLogoutCache(array $config): array
124+
{
125+
$backchannelLogoutCache = $config['backchannelLogoutCache'] ?? null;
126+
127+
if (false === $backchannelLogoutCache) {
128+
unset($config['backchannelLogoutCache']);
129+
130+
return $config;
131+
}
132+
133+
if (null === $backchannelLogoutCache) {
134+
$backchannelLogoutCache = $this->getBackchannelLogoutCachePool();
135+
}
136+
137+
if (is_string($backchannelLogoutCache)) {
138+
$backchannelLogoutCache = app(trim($backchannelLogoutCache));
139+
}
140+
141+
$config['backchannelLogoutCache'] = $backchannelLogoutCache instanceof CacheItemPoolInterface ? $backchannelLogoutCache : null;
142+
143+
return $config;
144+
}
145+
122146
protected function bootManagementTokenCache(array $config): array
123147
{
124148
$managementTokenCache = $config['managementTokenCache'] ?? null;
@@ -256,6 +280,15 @@ protected function createConfiguration(
256280
return $sdkConfiguration;
257281
}
258282

283+
protected function getBackchannelLogoutCachePool(): CacheItemPoolInterface
284+
{
285+
if (! $this->backchannelLogoutCachePool instanceof CacheItemPoolInterface) {
286+
$this->backchannelLogoutCachePool = app(CacheBridge::class);
287+
}
288+
289+
return $this->backchannelLogoutCachePool;
290+
}
291+
259292
protected function getManagementTokenCachePool(): CacheItemPoolInterface
260293
{
261294
if (! $this->managementTokenCachePool instanceof CacheItemPoolInterface) {

tests/Unit/ServiceTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,29 @@
188188
->tokenCache->toBeInstanceOf(CacheItemPoolInterface::class);
189189
});
190190

191+
test('bootBackchannelLogoutCache() behaves as expected', function (): void {
192+
$method = new ReflectionMethod(Service::class, 'bootBackchannelLogoutCache');
193+
$method->setAccessible(true);
194+
195+
expect($method->invoke($this->laravel, []))
196+
->backchannelLogoutCache->toBeInstanceOf(CacheBridgeContract::class);
197+
198+
expect($method->invoke($this->laravel, ['backchannelLogoutCache' => null]))
199+
->backchannelLogoutCache->toBeInstanceOf(CacheBridgeContract::class);
200+
201+
expect($method->invoke($this->laravel, ['backchannelLogoutCache' => CacheBridge::class]))
202+
->backchannelLogoutCache->toBeInstanceOf(CacheBridgeContract::class);
203+
204+
expect($method->invoke($this->laravel, ['backchannelLogoutCache' => false]))
205+
->backchannelLogoutCache->toBeNull();
206+
207+
expect($method->invoke($this->laravel, ['backchannelLogoutCache' => MemoryStore::class]))
208+
->backchannelLogoutCache->toBeNull();
209+
210+
expect($method->invoke($this->laravel, ['backchannelLogoutCache' => 'cache.psr6']))
211+
->backchannelLogoutCache->toBeInstanceOf(CacheItemPoolInterface::class);
212+
});
213+
191214
// test('bootManagementTokenCache() behaves as expected', function (): void {
192215
// $method = new ReflectionMethod(Service::class, 'bootManagementTokenCache');
193216
// $method->setAccessible(true);

0 commit comments

Comments
 (0)