mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-27 17:15:02 +00:00
refactor and rename classes
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph;
|
||||
|
||||
use Chill\MainBundle\Redis\ChillRedis;
|
||||
use League\OAuth2\Client\Token\AccessTokenInterface;
|
||||
use TheNetworg\OAuth2\Client\Provider\Azure;
|
||||
use TheNetworg\OAuth2\Client\Token\AccessToken;
|
||||
|
||||
class MachineTokenStorage
|
||||
{
|
||||
private const KEY = 'msgraph_access_token';
|
||||
|
||||
private ?AccessTokenInterface $accessToken = null;
|
||||
|
||||
private Azure $azure;
|
||||
|
||||
private ChillRedis $chillRedis;
|
||||
|
||||
public function __construct(Azure $azure, ChillRedis $chillRedis)
|
||||
{
|
||||
$this->azure = $azure;
|
||||
$this->chillRedis = $chillRedis;
|
||||
}
|
||||
|
||||
public function getToken(): AccessTokenInterface
|
||||
{
|
||||
if (null === $this->accessToken || $this->accessToken->hasExpired()) {
|
||||
$this->accessToken = $this->azure->getAccessToken('client_credentials', [
|
||||
'scope' => 'https://graph.microsoft.com/.default',
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
public function storeToken(AccessToken $token): void
|
||||
{
|
||||
$this->chillRedis->set(self::KEY, serialize($token));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user