0
0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2024-11-24 00:29:35 +00:00
salesagility_SuiteCRM/Api/V8/Service/LogoutService.php
2023-07-18 15:53:08 +01:00

52 lines
1.3 KiB
PHP

<?php
namespace Api\V8\Service;
use Api\V8\BeanDecorator\BeanManager;
use Api\V8\JsonApi\Response\DocumentResponse;
use Api\V8\JsonApi\Response\MetaResponse;
#[\AllowDynamicProperties]
class LogoutService
{
/**
* @var BeanManager
*/
protected $beanManager;
/**
* @param BeanManager $beanManager
*/
public function __construct(BeanManager $beanManager)
{
$this->beanManager = $beanManager;
}
/**
* @param string $accessToken
*
* @return DocumentResponse
* @throws \InvalidArgumentException When access token is not found.
*/
public function logout($accessToken)
{
// same logic in Access and Refresh token repository, refactor this later
$token = $this->beanManager->newBeanSafe(\OAuth2Tokens::class);
$token->retrieve_by_string_fields(
['access_token' => $accessToken]
);
if ($token->id === null) {
throw new \InvalidArgumentException('Access token is not found for this client');
}
$token->mark_deleted($token->id);
$response = new DocumentResponse();
$response->setMeta(
new MetaResponse(['message' => 'You have been successfully logged out'])
);
return $response;
}
}