This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: VOL-5650 introduce reusable access token provider, switch Trans…
…Xchange to use it
- Loading branch information
Showing
32 changed files
with
147 additions
and
891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Service\AccessToken; | ||
|
||
use League\OAuth2\Client\Token\AccessToken; | ||
use League\OAuth2\Client\Token\AccessTokenInterface; | ||
|
||
class Provider | ||
{ | ||
public function __construct(private readonly AccessToken|AccessTokenInterface $accessToken) | ||
{ | ||
} | ||
|
||
public function getToken(): string | ||
{ | ||
return $this->accessToken->getToken(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Service\AccessToken; | ||
|
||
use Laminas\ServiceManager\Factory\FactoryInterface; | ||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException; | ||
use League\OAuth2\Client\Provider\GenericProvider; | ||
use Olcs\Logging\Log\Logger; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class ProviderFactory implements FactoryInterface | ||
{ | ||
public const MSG_ERROR = 'Failed to retrieve access token for %s: %s'; | ||
|
||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Provider | ||
{ | ||
$providerConfig = [ | ||
'clientId' => $options['client_id'], | ||
'clientSecret' => $options['client_secret'], | ||
'urlAccessToken' => $options['token_url'], | ||
'urlAuthorize' => $options['token_url'], | ||
'urlResourceOwnerDetails' => $options['token_url'], | ||
]; | ||
|
||
if (isset($options['proxy'])) { | ||
$providerConfig['proxy'] = $options['proxy']; | ||
} | ||
|
||
$provider = new GenericProvider($providerConfig); | ||
|
||
try { | ||
$accessToken = $provider->getAccessToken('client_credentials', ['scope' => $options['scope']]); | ||
return new Provider($accessToken); | ||
} catch (IdentityProviderException $e) { | ||
$message = sprintf(self::MSG_ERROR, $options['service_name'], $e->getMessage()); | ||
Logger::err($message); | ||
throw $e; | ||
} | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
module/Api/src/Service/AppRegistration/Adapter/AppRegistrationSecret.php
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
module/Api/src/Service/AppRegistration/Adapter/AppRegistrationSecretFactory.php
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
module/Api/src/Service/AppRegistration/AppRegistrationInterface.php
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
module/Api/src/Service/AppRegistration/AppRegistrationServiceFactory.php
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
module/Api/src/Service/AppRegistration/GetAccessTokenTrait.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.