Skip to content

Commit f7f051b

Browse files
committed
add endSessionEndpoint to configuration to support ending the session
1 parent 8e668d7 commit f7f051b

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

src/OpenIDConfiguration/OpenIDConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function __construct(
5858
public array $idTokenSigningAlgValuesSupported = [],
5959
public string $userinfoEndpoint = '',
6060
public array $codeChallengeMethodsSupported = [],
61+
public string $endSessionEndpoint = '',
6162
) {
6263
}
6364
}

src/OpenIDConfiguration/OpenIDConfigurationLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ protected function getConfigurationFromIssuer(): OpenIDConfiguration
9191
subjectTypesSupported: $response->json('subject_types_supported', []),
9292
idTokenSigningAlgValuesSupported: $response->json('id_token_signing_alg_values_supported', []),
9393
userinfoEndpoint: $response->json('userinfo_endpoint', ''),
94-
codeChallengeMethodsSupported: $response->json('code_challenge_methods_supported', [])
94+
codeChallengeMethodsSupported: $response->json('code_challenge_methods_supported', []),
95+
endSessionEndpoint: $response->json('end_session_endpoint', ''),
9596
);
9697
}
9798

tests/Feature/Http/Controllers/LoginControllerResponseTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ protected function exampleOpenIDConfiguration(
620620
idTokenSigningAlgValuesSupported: ["RS256"],
621621
userinfoEndpoint: "https://provider.example.com/userinfo",
622622
codeChallengeMethodsSupported: $codeChallengeMethodsSupported,
623+
endSessionEndpoint: "https://provider.example.com/endSession",
623624
);
624625
}
625626

tests/Feature/Http/Controllers/LoginControllerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ protected function exampleOpenIDConfiguration(): OpenIDConfiguration
149149
idTokenSigningAlgValuesSupported: ["RS256"],
150150
userinfoEndpoint: "https://provider.example.com/userinfo",
151151
codeChallengeMethodsSupported: ["S256"],
152+
endSessionEndpoint: "https://provider.example.com/endSession",
152153
);
153154
}
154155
}

tests/Feature/OpenIDConfiguration/OpenIDConfigurationLoaderTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testConfigurationIsLoaded(): void
3838
$this->assertSame("https://provider.example.com/jwks", $configuration->jwksUri);
3939
$this->assertSame("https://provider.example.com/token", $configuration->tokenEndpoint);
4040
$this->assertSame("https://provider.example.com/userinfo", $configuration->userinfoEndpoint);
41+
$this->assertSame("https://provider.example.com/logout", $configuration->endSessionEndpoint);
4142
}
4243

4344
public function testConfigurationIsLoadedMultipleTimesWhenNotCached(): void
@@ -60,6 +61,7 @@ public function testConfigurationIsLoadedMultipleTimesWhenNotCached(): void
6061
$this->assertSame("https://provider.example.com/jwks", $configuration->jwksUri);
6162
$this->assertSame("https://provider.example.com/token", $configuration->tokenEndpoint);
6263
$this->assertSame("https://provider.example.com/userinfo", $configuration->userinfoEndpoint);
64+
$this->assertSame("https://provider.example.com/logout", $configuration->endSessionEndpoint);
6365
}
6466

6567
public function testConfigurationIsCached(): void
@@ -87,6 +89,7 @@ public function testConfigurationIsCached(): void
8789
$this->assertSame("https://provider.example.com/jwks", $configuration->jwksUri);
8890
$this->assertSame("https://provider.example.com/token", $configuration->tokenEndpoint);
8991
$this->assertSame("https://provider.example.com/userinfo", $configuration->userinfoEndpoint);
92+
$this->assertSame("https://provider.example.com/logout", $configuration->endSessionEndpoint);
9093
}
9194

9295
public function testLoaderThrowsExceptionWhenProviderReturns400ResponseCode(): void
@@ -198,6 +201,7 @@ public function testLoaderReturnsEmptyConfigurationOnEmptyJsonResponse(): void
198201
$this->assertEmpty($configuration->authorizationEndpoint);
199202
$this->assertEmpty($configuration->jwksUri);
200203
$this->assertEmpty($configuration->tokenEndpoint);
204+
$this->assertEmpty($configuration->userinfoEndpoint);
201205
}
202206

203207
public function testConfigurationIsLoadedMultipleTimesWhenCacheStoreIsNull(): void
@@ -221,6 +225,7 @@ public function testConfigurationIsLoadedMultipleTimesWhenCacheStoreIsNull(): vo
221225
$this->assertSame("https://provider.example.com/jwks", $configuration->jwksUri);
222226
$this->assertSame("https://provider.example.com/token", $configuration->tokenEndpoint);
223227
$this->assertSame("https://provider.example.com/userinfo", $configuration->userinfoEndpoint);
228+
$this->assertSame("https://provider.example.com/logout", $configuration->endSessionEndpoint);
224229
}
225230

226231
protected function fakeSuccessfulResponse(): void
@@ -264,7 +269,8 @@ protected function fakeSuccessfulResponse(): void
264269
],
265270
"code_challenge_methods_supported" => [
266271
"S256"
267-
]
272+
],
273+
"end_session_endpoint" => "https://provider.example.com/logout"
268274
])
269275
]);
270276
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MinVWS\OpenIDConnectLaravel\Tests\Feature;
6+
7+
use Illuminate\Http\Exceptions\HttpResponseException;
8+
use Illuminate\Support\Facades\Config;
9+
use Illuminate\Support\Facades\Http;
10+
use MinVWS\OpenIDConnectLaravel\OpenIDConnectClient;
11+
use MinVWS\OpenIDConnectLaravel\Tests\TestCase;
12+
use Symfony\Component\HttpFoundation\Response;
13+
14+
class OpenIDConnectClientTest extends TestCase
15+
{
16+
public function testSignOut(): void
17+
{
18+
Http::fake([
19+
'https://provider.example.com/.well-known/openid-configuration' => Http::response([
20+
"end_session_endpoint" => "https://provider.example.com/logout",
21+
])
22+
]);
23+
Config::set('oidc.issuer', 'https://provider.example.com');
24+
Config::set('oidc.configuration_cache.store', null);
25+
26+
$client = app(OpenIDConnectClient::class);
27+
28+
try {
29+
$client->signOut('idToken', 'redirect');
30+
} catch (HttpResponseException $e) {
31+
$this->assertEquals(Response::HTTP_FOUND, $e->getResponse()->getStatusCode());
32+
$this->assertEquals(
33+
'https://provider.example.com/logout?id_token_hint=idToken&post_logout_redirect_uri=redirect',
34+
$e->getResponse()->getTargetUrl()
35+
);
36+
37+
return;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)