Get session from requestStack instead of injecting SessionInterface

This commit is contained in:
2025-05-26 14:19:01 +02:00
parent 6e5dbe4e58
commit 5cdfee40fb
3 changed files with 29 additions and 31 deletions

View File

@@ -18,7 +18,7 @@ declare(strict_types=1);
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use TheNetworg\OAuth2\Client\Provider\Azure;
use TheNetworg\OAuth2\Client\Token\AccessToken;
@@ -29,12 +29,12 @@ class OnBehalfOfUserTokenStorage
{
final public const MS_GRAPH_ACCESS_TOKEN = 'msgraph_access_token';
public function __construct(private readonly Azure $azure, private readonly SessionInterface $session) {}
public function __construct(private readonly Azure $azure, private readonly RequestStack $requestStack) {}
public function getToken(): AccessToken
{
/** @var ?AccessToken $token */
$token = $this->session->get(self::MS_GRAPH_ACCESS_TOKEN, null);
$token = $this->requestStack->getSession()->get(self::MS_GRAPH_ACCESS_TOKEN, null);
if (null === $token) {
throw new \LogicException('unexisting token');
@@ -53,11 +53,11 @@ class OnBehalfOfUserTokenStorage
public function hasToken(): bool
{
return $this->session->has(self::MS_GRAPH_ACCESS_TOKEN);
return $this->requestStack->getSession()->has(self::MS_GRAPH_ACCESS_TOKEN);
}
public function setToken(AccessToken $token): void
{
$this->session->set(self::MS_GRAPH_ACCESS_TOKEN, $token);
$this->requestStack->getSession()->set(self::MS_GRAPH_ACCESS_TOKEN, $token);
}
}