- Added SearchRequest compatibilty and began working on QueryBuilder processing

This commit is contained in:
Dave Mc Nicoll committed 2024-04-17 15:57:51 -04:00
1 parent ce4d6cdf7c
commit 4e120cea6c
20 files changed
+510 -141

No files matched your search

+34 -25
View File
@@ -7,39 +7,43 @@ use Ulmus\Api\Common\AuthenticationEnum;
class CurlAuthorization
{
public array $headers = [];
public function __construct(
#[\SensitiveParameter]
public array $configuration,
#[\SensitiveParameter]
public array $headers = [],
public array $options = [],
) { }
public array $options = [];
public function fromAuthenticationEnum(AuthenticationEnum $auth, #[\SensitiveParameter] array $configuration,) : static
public function fromAuthenticationEnum(AuthenticationEnum $auth,) : static
{
switch($auth) {
case AuthenticationEnum::Bearer:
$this->bearer($configuration['token']);
$this->bearer($this->configuration['token']);
break;
case AuthenticationEnum::Key:
$this->key($configuration['token']);
$this->key($this->configuration['token']);
break;
case AuthenticationEnum::Token:
$this->token($configuration['token']);
$this->token($this->configuration['token']);
break;
case AuthenticationEnum::Basic:
$this->basic($configuration['username'], $configuration['password']);
$this->basic($this->configuration['username'], $this->configuration['password']);
break;
case AuthenticationEnum::Ntlm:
$this->ntlm($configuration['username'], $configuration['password']);
$this->ntlm($this->configuration['username'], $this->configuration['password']);
break;
case AuthenticationEnum::Negotiate:
$this->negotiate($configuration['username'], $configuration['password']);
$this->negotiate($this->configuration['username'], $this->configuration['password']);
break;
case AuthenticationEnum::OAuth2:
$this->oauth2($configuration['grant'], $configuration['oauth_token_url'], $configuration['redirect_uri'], $configuration['client_id'], $configuration['client_secret'], $configuration['scope']);
$this->oauth2($this->configuration['grant'], $this->configuration['oauth_token_url'], $this->configuration['redirect_uri'], $this->configuration['client_id'], $this->configuration['client_secret'], $this->configuration['scope']);
break;
}
@@ -94,11 +98,11 @@ class CurlAuthorization
public function oauth2(Oauth2GrantTypeEnum $grant, string $oauthTokenUrl, string $redirectUri, string $clientId, string $clientSecret, string $scope) : void
{
#return;
$unid = sprintf("oauth_token_%s", md5(serialize($this->configuration)));
# TMP !
if (false === ($_SESSION['grics_token'] ?? false)) {
# IF NO TOKEN OR TIMEOUT
$token = apcu_fetch($unid, $exists);
if ( ! $exists ) {
$provider = new GenericProvider([
'clientId' => $clientId,
'clientSecret' => $clientSecret,
@@ -111,22 +115,27 @@ class CurlAuthorization
try {
$accessToken = $provider->getAccessToken($grant->value);
$_SESSION['grics_token'] = $accessToken->getToken();
$token = json_encode($accessToken);
# var_dump($accessToken); die();
# KEEP TOKEN IN APCU !
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token
exit($e->getMessage());
apcu_store($unid, $token, $accessToken->getExpires() - time() - 10);
}
catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
throw $e;
}
}
try {
$decodedToken = json_decode($token, true, 512, JSON_THROW_ON_ERROR);
}
catch(\Exception $ex) {
throw new \InvalidArgumentException("Given OAuth2 token is not a parsable JSON stream.");
}
$this->bearer($_SESSION['grics_token']);
if ( empty($decodedToken) ) {
throw new \InvalidArgumentException("Given OAuth Token is empty");
}
#var_dump($_SESSION['grics_token']);die();
# SWITCH TO BEARER AUTH TYPE, SET TOKEN FROM APCU IF STILL VALID
$this->bearer($decodedToken['access_token']);
}
protected function userpass(int $authType, string $username, #[\SensitiveParameter] $password) : void