|
@@ -2,11 +2,12 @@
|
|
|
namespace Opentalent\OtConnect\Service;
|
|
namespace Opentalent\OtConnect\Service;
|
|
|
|
|
|
|
|
use DateTime;
|
|
use DateTime;
|
|
|
-use GuzzleHttp\Client;
|
|
|
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
use GuzzleHttp\Cookie\CookieJar;
|
|
|
use GuzzleHttp\Cookie\SetCookie;
|
|
use GuzzleHttp\Cookie\SetCookie;
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
use GuzzleHttp\Exception\RequestException;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
|
|
|
+use Opentalent\OtCore\Exception\ApiRequestException;
|
|
|
|
|
+use Opentalent\OtCore\Service\OpentalentApiService;
|
|
|
use TYPO3\CMS\Core\Crypto\Random;
|
|
use TYPO3\CMS\Core\Crypto\Random;
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
|
|
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
|
|
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
|
|
@@ -19,16 +20,13 @@ use \TYPO3\CMS\Core\Authentication\AbstractAuthenticationService;
|
|
|
*/
|
|
*/
|
|
|
class OtAuthenticationService extends AbstractAuthenticationService
|
|
class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
- CONST DOMAIN = 'https://api.opentalent.fr';
|
|
|
|
|
- CONST API_URI = self::DOMAIN . '/api/';
|
|
|
|
|
- CONST LOGIN_URI = self::API_URI . 'login_check';
|
|
|
|
|
- CONST GET_USER_DATA_URI = self::API_URI . 'user/datafortypo3';
|
|
|
|
|
- CONST ISAUTH_URI = self::API_URI . 'user/isauthenticated';
|
|
|
|
|
- CONST LOGOUT_URI = self::API_URI . 'logout';
|
|
|
|
|
|
|
+ CONST LOGIN_URI = 'api/login_check';
|
|
|
|
|
+ CONST GET_USER_DATA_URI = 'api/user/datafortypo3';
|
|
|
|
|
+ CONST ISAUTH_URI = 'api/user/isauthenticated';
|
|
|
|
|
+ CONST LOGOUT_URI = 'api/logout';
|
|
|
CONST GROUP_FE_ALL_UID = 18076;
|
|
CONST GROUP_FE_ALL_UID = 18076;
|
|
|
|
|
|
|
|
- // Cookies'domain needs to be the same that the api's cookies, or guzzle will ignore them.
|
|
|
|
|
|
|
+ // Cookies' domain needs to be the same that the api's cookies, or guzzle will ignore them.
|
|
|
CONST COOKIE_DOMAIN = 'opentalent.fr';
|
|
CONST COOKIE_DOMAIN = 'opentalent.fr';
|
|
|
|
|
|
|
|
CONST PRODUCT_MAPPING = [
|
|
CONST PRODUCT_MAPPING = [
|
|
@@ -70,12 +68,9 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
const STATUS_AUTHENTICATION_SUCCESS = 200;
|
|
const STATUS_AUTHENTICATION_SUCCESS = 200;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * Guzzle Client
|
|
|
|
|
- *
|
|
|
|
|
- * @see http://docs.guzzlephp.org/en/stable/
|
|
|
|
|
- * @var Client
|
|
|
|
|
|
|
+ * @var object
|
|
|
*/
|
|
*/
|
|
|
- private Client $client;
|
|
|
|
|
|
|
+ private object $apiService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Guzzle Cookie Jar
|
|
* Guzzle Cookie Jar
|
|
@@ -99,7 +94,7 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
*/
|
|
*/
|
|
|
public function __construct() {
|
|
public function __construct() {
|
|
|
$this->jar = new CookieJar;
|
|
$this->jar = new CookieJar;
|
|
|
- $this->client = new Client(['base_uri' => self::DOMAIN, 'cookies' => $this->jar]);
|
|
|
|
|
|
|
+ $this->apiService = GeneralUtility::makeInstance(OpentalentApiService::class, null, null, $this->jar);
|
|
|
$this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
|
|
$this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -177,7 +172,7 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
{
|
|
{
|
|
|
$this->fillCookieJar();
|
|
$this->fillCookieJar();
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->client->request('GET', self::ISAUTH_URI, ['cookies' => $this->jar]);
|
|
|
|
|
|
|
+ $response = $this->apiService->get(self::ISAUTH_URI, [], ['cookies' => $this->jar]);
|
|
|
|
|
|
|
|
if ($response->getStatusCode() != 200) {
|
|
if ($response->getStatusCode() != 200) {
|
|
|
return null;
|
|
return null;
|
|
@@ -185,10 +180,9 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
|
|
|
|
|
return json_decode((string)$response->getBody());
|
|
return json_decode((string)$response->getBody());
|
|
|
|
|
|
|
|
- } catch (RequestException $e) {
|
|
|
|
|
|
|
+ } catch (ApiRequestException $e) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -221,7 +215,7 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->client->request(
|
|
|
|
|
|
|
+ $response = $this->apiService->request(
|
|
|
'POST',
|
|
'POST',
|
|
|
self::LOGIN_URI,
|
|
self::LOGIN_URI,
|
|
|
['form_params' => ['_username' => $username, '_password' => $password]]
|
|
['form_params' => ['_username' => $username, '_password' => $password]]
|
|
@@ -237,7 +231,7 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
$this->setCookiesFromApiResponse($response);
|
|
$this->setCookiesFromApiResponse($response);
|
|
|
return true;
|
|
return true;
|
|
|
|
|
|
|
|
- } catch (RequestException $e) {
|
|
|
|
|
|
|
+ } catch (ApiRequestException $e) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -353,14 +347,12 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
*
|
|
*
|
|
|
* @return array
|
|
* @return array
|
|
|
*/
|
|
*/
|
|
|
- protected function getUserData(): array
|
|
|
|
|
|
|
+ protected function getUserData(): ?array
|
|
|
{
|
|
{
|
|
|
$this->fillCookieJar();
|
|
$this->fillCookieJar();
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->client->request('GET', self::GET_USER_DATA_URI, ['cookies' => $this->jar]);
|
|
|
|
|
- } catch (RequestException $e) {
|
|
|
|
|
- return [];
|
|
|
|
|
- } catch (GuzzleException $e) {
|
|
|
|
|
|
|
+ $response = $this->apiService->request('GET', self::GET_USER_DATA_URI, [], ['cookies' => $this->jar]);
|
|
|
|
|
+ } catch (ApiRequestException $e) {
|
|
|
return [];
|
|
return [];
|
|
|
}
|
|
}
|
|
|
return json_decode($response->getBody(), true);
|
|
return json_decode($response->getBody(), true);
|
|
@@ -401,7 +393,7 @@ class OtAuthenticationService extends AbstractAuthenticationService
|
|
|
public function logout(): bool
|
|
public function logout(): bool
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
- $response = $this->client->request(
|
|
|
|
|
|
|
+ $response = $this->apiService->request(
|
|
|
'GET',
|
|
'GET',
|
|
|
self::LOGOUT_URI
|
|
self::LOGOUT_URI
|
|
|
);
|
|
);
|