Skip to content

Commit 5af71fa

Browse files
authored
Merge pull request #1877 from gassan/fix-interactives-login
2 parents ecbff06 + 66b9522 commit 5af71fa

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Changelog
77
* Enhancement: (@internal) Removed/replaced redundant argument `$firewallNames` from controllers. If controller class was copied and replaced, adapt list of arguments: In controller use `$resourceOwnerMapLocator->getFirewallNames()`.
88
* Changed config files from `*.xml` to `*.php` (services and routes). Xml routing configs `connect.xml`, `login.xml` and `redirect.xml` are steel present but deprecated. Please use `*.php` variants in your includes instead.
99
* Bugfix: RefreshTokenListener can not be lazy. If current firewall is lazy (or anonymous: lazy) then current auth token is often initializing on `kernel.response`. In this case new access token will not be stored in session. Therefore the expired token will be refreshed on each request.
10+
* Bugfix: InteractiveLoginEvent will be triggered also for OAuthAuthenticator.
1011

1112
## 2.0.0-BETA1 (2021-12-10)
1213
* BC Break: Dropped PHP 7.3 support,

src/Security/Http/Authenticator/OAuthAuthenticator.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
3131
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
3232
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
33+
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
3334
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
3435
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
3536
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
@@ -38,7 +39,7 @@
3839
/**
3940
* @author Vadim Borodavko <[email protected]>
4041
*/
41-
final class OAuthAuthenticator implements AuthenticatorInterface, AuthenticationEntryPointInterface
42+
final class OAuthAuthenticator implements AuthenticatorInterface, AuthenticationEntryPointInterface, InteractiveAuthenticatorInterface
4243
{
4344
private HttpUtils $httpUtils;
4445
private OAuthAwareUserProviderInterface $userProvider;
@@ -262,6 +263,11 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
262263
return $this->failureHandler->onAuthenticationFailure($request, $exception);
263264
}
264265

266+
public function isInteractive(): bool
267+
{
268+
return true;
269+
}
270+
265271
private function extractCsrfTokenFromState(?string $stateParameter): ?string
266272
{
267273
$state = new State($stateParameter);
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the HWIOAuthBundle package.
5+
*
6+
* (c) Hardware Info <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace HWI\Bundle\OAuthBundle\Tests\Fixtures;
13+
14+
class CustomEventListener
15+
{
16+
/**
17+
* @param mixed $event
18+
*/
19+
public function handle($event): void
20+
{
21+
}
22+
}

tests/Functional/IntegrationTest.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
namespace HWI\Bundle\OAuthBundle\Tests\Functional;
1515

1616
use HWI\Bundle\OAuthBundle\Tests\App\AppKernel;
17+
use HWI\Bundle\OAuthBundle\Tests\Fixtures\CustomEventListener;
1718
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1819
use Symfony\Component\HttpClient\MockHttpClient;
1920
use Symfony\Component\HttpClient\Response\MockResponse;
2021
use Symfony\Component\HttpFoundation\Response;
22+
use Symfony\Component\Security\Http\SecurityEvents;
2123

2224
final class IntegrationTest extends WebTestCase
2325
{
@@ -85,7 +87,20 @@ function ($method, $url, $options) {
8587

8688
$client = static::createClient();
8789
$client->disableReboot();
88-
$client->getContainer()->set('hwi_oauth.http_client', $httpClient);
90+
$container = $client->getContainer();
91+
$container->set('hwi_oauth.http_client', $httpClient);
92+
93+
$interactiveLoginListener = $this->createMock(CustomEventListener::class);
94+
$interactiveLoginListener->expects($this->once())->method('handle');
95+
// We attach our custom listener to prove InteractiveLoginEvent fired correctly.
96+
// 'security.event_dispatcher.main' Dispatcher is used for Symfony 5.4 and 6.0 under php ^8.0 and ^8.1
97+
// and 'event_dispatcher' for all 4.4 and 5.4 under ^7.4
98+
foreach (['security.event_dispatcher.main', 'event_dispatcher'] as $dispatcherId) {
99+
if ($container->has($dispatcherId)) {
100+
$container->get($dispatcherId)
101+
->addListener(SecurityEvents::INTERACTIVE_LOGIN, [$interactiveLoginListener, 'handle']);
102+
}
103+
}
89104

90105
$client->request('GET', $redirectLoginFromService);
91106

0 commit comments

Comments
 (0)