Skip to content

Commit a8c838e

Browse files
Fixing usage of session.attribute_bag: simply using request.session instead
1 parent 14c7f4b commit a8c838e

2 files changed

Lines changed: 7 additions & 31 deletions

File tree

Action/RedirectUrlSetterAction.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\HttpFoundation\RedirectResponse;
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
18-
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
1918
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2019

2120
/**
@@ -25,17 +24,6 @@
2524
*/
2625
class RedirectUrlSetterAction
2726
{
28-
/** @var AttributeBagInterface */
29-
protected $attributeBag;
30-
31-
/**
32-
* @param AttributeBagInterface $attributeBag
33-
*/
34-
public function __construct(AttributeBagInterface $attributeBag)
35-
{
36-
$this->attributeBag = $attributeBag;
37-
}
38-
3927
/**
4028
* @param Request $request
4129
*
@@ -47,7 +35,10 @@ public function __invoke(Request $request): Response
4735
if (!$redirectUrl) {
4836
throw new NotFoundHttpException('Missing redirectUrl in query');
4937
}
50-
$this->attributeBag->set(AuthenticationSuccessHandler::SESSION_KEY, $redirectUrl);
38+
$session = $request->getSession();
39+
if ($session) {
40+
$session->set(AuthenticationSuccessHandler::SESSION_KEY, $redirectUrl);
41+
}
5142

5243
if ($request->isXmlHttpRequest()) {
5344
return new JsonResponse();

Security/Http/Authentication/AuthenticationSuccessHandler.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
namespace CleverAge\OAuthApiBundle\Security\Http\Authentication;
1212

1313
use Symfony\Component\HttpFoundation\Request;
14-
use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface;
1514
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1615
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
17-
use Symfony\Component\Security\Http\HttpUtils;
1816

1917
/**
2018
* Redirect to URL in session if any else use default Symfony behaviour
@@ -26,27 +24,14 @@ class AuthenticationSuccessHandler extends DefaultAuthenticationSuccessHandler
2624
/** @var string */
2725
public const SESSION_KEY = 'sso_redirect_url';
2826

29-
/** @var AttributeBagInterface */
30-
protected $attributeBag;
31-
32-
/**
33-
* @param HttpUtils $httpUtils
34-
* @param array $options
35-
* @param AttributeBagInterface $attributeBag
36-
*/
37-
public function __construct(HttpUtils $httpUtils, array $options = [], AttributeBagInterface $attributeBag = null)
38-
{
39-
parent::__construct($httpUtils, $options);
40-
$this->attributeBag = $attributeBag;
41-
}
42-
4327
/**
4428
* {@inheritDoc}
4529
*/
4630
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
4731
{
48-
if ($this->attributeBag->has(self::SESSION_KEY)) {
49-
$redirectUrl = $this->attributeBag->get(self::SESSION_KEY);
32+
$session = $request->getSession();
33+
if ($session && $session->has(self::SESSION_KEY)) {
34+
$redirectUrl = $session->get(self::SESSION_KEY);
5035
if ($redirectUrl) {
5136
return $this->httpUtils->createRedirectResponse($request, $redirectUrl);
5237
}

0 commit comments

Comments
 (0)