• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TYPO3GmbH / symfony-keycloak-bundle / 14440499152

14 Apr 2025 08:01AM UTC coverage: 4.425% (-0.3%) from 4.739%
14440499152

Pull #20

github

web-flow
Merge 27517d3b7 into 464b21466
Pull Request #20: [BUGFIX] Add logout event listener for SSO logout

0 of 22 new or added lines in 5 files covered. (0.0%)

10 of 226 relevant lines covered (4.42%)

9.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Service/RedirectService.php
1
<?php
2
declare(strict_types=1);
3

4
/*
5
 * This file is part of the package t3g/symfony-keycloak-bundle.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE file that was distributed with this source code.
9
 */
10

11
namespace T3G\Bundle\Keycloak\Service;
12

13
use KnpU\OAuth2ClientBundle\Client\ClientRegistry;
14
use KnpU\OAuth2ClientBundle\Client\OAuth2Client;
15
use Stevenmaguire\OAuth2\Client\Provider\Keycloak;
16
use Symfony\Component\HttpFoundation\RedirectResponse;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19
use Symfony\Component\Routing\RouterInterface;
20

21
class RedirectService
22
{
23
    public const DEFAULT_SCOPES = ['openid', 'profile', 'roles', 'email'];
24
    private ClientRegistry $clientRegistry;
25
    private RouterInterface $router;
26
    private OpenIdService $openIdService;
27
    private string $clientId;
28

29
    public function __construct(ClientRegistry $clientRegistry, RouterInterface $router, OpenIdService $openIdService, string $clientId)
30
    {
31
        $this->clientRegistry = $clientRegistry;
×
32
        $this->clientId = $clientId;
×
NEW
33
        $this->openIdService = $openIdService;
×
NEW
34
        $this->router = $router;
×
35
    }
36

37
    /**
38
     * @param string[] $scopes
39
     */
40
    public function generateLoginRedirectResponse(array $scopes = self::DEFAULT_SCOPES): RedirectResponse
41
    {
42
        /** @var OAuth2Client $client */
43
        $client = $this->clientRegistry->getClient('keycloak');
×
44

45
        return $client->redirect($scopes);
×
46
    }
47

48
    public function generateLogoutRedirectResponse($logoutRoute): RedirectResponse
49
    {
NEW
50
        $redirectAfterOAuthLogout = rtrim($this->router->generate($logoutRoute, [], UrlGeneratorInterface::ABSOLUTE_URL), '/');
×
51
        /** @var Keycloak $provider */
52
        $provider = $this->clientRegistry->getClient('keycloak')->getOAuth2Provider();
×
NEW
53
        $openIdConfiguration = $this->openIdService->getOpenIdConfiguration(sprintf('%s/realms/%s', $provider->authServerUrl, $provider->realm));
×
54
        $redirectTarget = sprintf(
×
NEW
55
            '%s?client_id=%s&post_logout_redirect_uri=%s',
×
NEW
56
            $openIdConfiguration['end_session_endpoint'],
×
57
            $this->clientId,
×
58
            urlencode($redirectAfterOAuthLogout)
×
59
        );
×
60

61
        return new RedirectResponse($redirectTarget, Response::HTTP_TEMPORARY_REDIRECT);
×
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc