diff --git a/Auth/OAuth2/Grant/AuthorizationCode.php b/Auth/OAuth2/Grant/AuthorizationCode.php deleted file mode 100644 index 65941315d..000000000 --- a/Auth/OAuth2/Grant/AuthorizationCode.php +++ /dev/null @@ -1,38 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class AuthorizationCode extends GrantAbstract -{ - protected function getName() : string - { - return 'authorization_code'; - } - - protected function getRequiredRequestParameters() : array - { - return ['code']; - } -} diff --git a/Auth/OAuth2/Grant/ClientCredentials.php b/Auth/OAuth2/Grant/ClientCredentials.php deleted file mode 100644 index 92715d91d..000000000 --- a/Auth/OAuth2/Grant/ClientCredentials.php +++ /dev/null @@ -1,38 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class ClientCredentials extends GrantAbstract -{ - protected function getName() : string - { - return 'client_credentials'; - } - - protected function getRequiredRequestParameters() : array - { - return []; - } -} diff --git a/Auth/OAuth2/Grant/GrantAbstract.php b/Auth/OAuth2/Grant/GrantAbstract.php deleted file mode 100644 index 41d9eab25..000000000 --- a/Auth/OAuth2/Grant/GrantAbstract.php +++ /dev/null @@ -1,53 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -abstract class GrantAbstract -{ - abstract protected function getName() : string; - - abstract protected function getRequiredRequestParameters() : array; - - public function __toString() - { - return $this->getName(); - } - - public function prepareRequestParamters(array $defaults, array $options) : array - { - $defaullts['grant_type'] = $this->getName(); - - $required = $this->getRequiredRequestParameters(); - $provided = \array_merge($defaults, $options); - - foreach ($required as $name) { - if (!isset($provided[$name])) { - throw new \Exception(); - } - } - - return $provided; - } -} diff --git a/Auth/OAuth2/Grant/GrantFactory.php b/Auth/OAuth2/Grant/GrantFactory.php deleted file mode 100644 index cadb6ca6a..000000000 --- a/Auth/OAuth2/Grant/GrantFactory.php +++ /dev/null @@ -1,58 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class GrantFactory -{ - protected array $registry = []; - - public function setGrant(string $name, GrantAbstract $grant) : self - { - $this->registry[$name] = $grant; - - return $this; - } - - public function getGrant(string $name) : GrantAbstract - { - if (!isset($this->registry[$name])) { - $this->registerDefaultGrant($name); - } - - return $this->registry[$name]; - } - - protected function registerDefaultGrant(string $name) : self - { - $class = \str_replace(' ', '', \ucwords(\str_replace(['-', '_'], ' ', $name))); - $class = 'phpOMS\\Auth\\OAuth2\\Grant\\' . $class; - - if (!\is_subclass_of($class, GrantAbstract::class)) { - throw new \Exception(); - } - - return $this->setGrant($name, new $class()); - } -} diff --git a/Auth/OAuth2/Grant/Password.php b/Auth/OAuth2/Grant/Password.php deleted file mode 100644 index 3155455a1..000000000 --- a/Auth/OAuth2/Grant/Password.php +++ /dev/null @@ -1,41 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class Password extends GrantAbstract -{ - protected function getName() : string - { - return 'password'; - } - - protected function getRequiredRequestParameters() : array - { - return [ - 'username', - 'password', - ]; - } -} diff --git a/Auth/OAuth2/Grant/RefreshToken.php b/Auth/OAuth2/Grant/RefreshToken.php deleted file mode 100644 index d027b84d3..000000000 --- a/Auth/OAuth2/Grant/RefreshToken.php +++ /dev/null @@ -1,38 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Grant; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Grant - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class RefreshToken extends GrantAbstract -{ - protected function getName() : string - { - return 'refresh_token'; - } - - protected function getRequiredRequestParameters() : array - { - return ['refresh_token']; - } -} diff --git a/Auth/OAuth2/OptionProvider/HttpBasicAuthOptionProvider.php b/Auth/OAuth2/OptionProvider/HttpBasicAuthOptionProvider.php deleted file mode 100644 index 01fb30bff..000000000 --- a/Auth/OAuth2/OptionProvider/HttpBasicAuthOptionProvider.php +++ /dev/null @@ -1,43 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\OptionProvider; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\OptionProvider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class HttpBasicAuthOptionProvider extends PostAuthOptionProvider -{ - public function getAccessTokenOptions(string $method, array $params) : array - { - if (!isset($params['client_id'], $params['client_secret'])) { - return []; - } - - $encoded = \base64_encode($params['client_id'] . ':' . $params['client_secret']); - unset($params['client_id'], $params['client_secret']); - - $options = parent::getAccessTokenOptions($method, $params); - $options['headers']['Authorization'] = 'Basic ' . $encoded; - - return $options; - } -} diff --git a/Auth/OAuth2/OptionProvider/OptionProviderInterface.php b/Auth/OAuth2/OptionProvider/OptionProviderInterface.php deleted file mode 100644 index 6a593974e..000000000 --- a/Auth/OAuth2/OptionProvider/OptionProviderInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\OptionProvider; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\OptionProvider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -interface OptionProviderInterface -{ - public function getAccessTokenOptions(string $method, array $params) : array; -} diff --git a/Auth/OAuth2/OptionProvider/PostAuthOptionProvider.php b/Auth/OAuth2/OptionProvider/PostAuthOptionProvider.php deleted file mode 100644 index 5a1e07d1b..000000000 --- a/Auth/OAuth2/OptionProvider/PostAuthOptionProvider.php +++ /dev/null @@ -1,49 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\OptionProvider; - -use phpOMS\Message\Http\RequestMethod; -use phpOMS\System\MimeType; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\OptionProvider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class PostAuthOptionProvider implements OptionProviderInterface -{ - public function getAccessTokenOptions(string $method, array $params) : array - { - $options = [ - 'headers' => ['content-type' => MimeType::M_POST], - ]; - - if ($method === RequestMethod::POST) { - $options['body'] = $this->getAccessTokenBody($params); - } - - return $options; - } - - protected function getAccessTokenBody(array $params) : string - { - return \http_build_query($params, '', '&', \PHP_QUERY_RFC3986); - } -} diff --git a/Auth/OAuth2/Provider/GeneralProvider.php b/Auth/OAuth2/Provider/GeneralProvider.php deleted file mode 100644 index 01f8606c8..000000000 --- a/Auth/OAuth2/Provider/GeneralProvider.php +++ /dev/null @@ -1,103 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Provider; - -use phpOMS\Auth\OAuth2\Token\AccessToken; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Provider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class GeneralProvider extends ProviderAbstract -{ - private string $urlAuthorize; - - private string $urlAccessToken; - - private string $urlResourceOwnerDetails; - - private string $accessTokenMethod; - - private string $accessTokenResourceOwnerId; - - private ?array $scopes = null; - - private string $scopeSeparator; - - private string $responseCode; - - private string $responseResourceOwnerId = 'id'; - - public function __construct(array $options = [], array $collaborators = []) - { - if (!isset($options['urlAuthorize'], $options['urlAccessToken'], $options['urlResourceOwnerDetails'])) { - throw new \InvalidArgumentException(); - } - - foreach ($options as $key => $option) { - if (\property_exists($this, $key)) { - $this->{$key} = $option; - } - } - - parent::__construct([], $collaborators); - } - - public function getBaseAuthorizationUrl() : string - { - return $this->urlAuthorize; - } - - public function getBaseAccessTokenUrl(array $params = []) : string - { - return $this->urlAccessToken; - } - - public function getResourceOwnerDetailsUrl(AccessToken $token) : string - { - return $this->urlResourceOwnerDetails; - } - - public function getDefaultScopes() : array - { - return $this->scopes; - } - - protected function getAccessTokenMethod() : string - { - return $this->accessTokenMethod ?: parent::getAccessTokenMethod(); - } - - protected function getAccessTokenResourceOwnerId() : string - { - return $this->accessTokenResourceOwnerId ?: parent::getAccessTokenResourceOwnerId(); - } - - protected function getScopeSeparator() : string - { - return $this->scopeSeparator ?: parent::getScopeSeparator(); - } - - protected function createResourceOwner(array $response, AccessToken $token) : GeneralResourceOwner - { - return new GeneralResourceOwner($response, $this->responseResourceOwnerId); - } -} diff --git a/Auth/OAuth2/Provider/GeneralResourceOwner.php b/Auth/OAuth2/Provider/GeneralResourceOwner.php deleted file mode 100644 index b2467abf7..000000000 --- a/Auth/OAuth2/Provider/GeneralResourceOwner.php +++ /dev/null @@ -1,48 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Provider; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Provider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class GeneralResourceOwner implements ResourceOwnerInterface -{ - protected array $response; - - protected string $resourceOwnerId; - - public function __construct(array $response, string $resourceOwnerId) - { - $this->response = $response; - $this->resourceOwnerId = $resourceOwnerId; - } - - public function getId() : string - { - return $this->response[$this->resourceOwnerId]; - } - - public function toArray() : array - { - return $this->response; - } -} diff --git a/Auth/OAuth2/Provider/ProviderAbstract.php b/Auth/OAuth2/Provider/ProviderAbstract.php deleted file mode 100644 index 66bafbf73..000000000 --- a/Auth/OAuth2/Provider/ProviderAbstract.php +++ /dev/null @@ -1,319 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Provider; - -use phpOMS\Auth\OAuth2\Grant\GrantAbstract; -use phpOMS\Auth\OAuth2\Grant\GrantFactory; -use phpOMS\Auth\OAuth2\OptionProvider\OptionProviderInterface; -use phpOMS\Auth\OAuth2\OptionProvider\PostAuthOptionProvider; -use phpOMS\Auth\OAuth2\Token\AccessToken; -use phpOMS\Auth\OAuth2\Token\AccessTokenInterface; -use phpOMS\Message\Http\HttpRequest; -use phpOMS\Message\Http\HttpResponse; -use phpOMS\Message\Http\RequestMethod; -use phpOMS\Uri\UriFactory; -use phpOMS\Utils\ArrayUtils; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Provider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -abstract class ProviderAbstract -{ - protected const ACCESS_TOKEN_RESOURCE_OWNER_ID = null; - - protected string $clientId; - - protected string $clientSecret; - - protected string $redirectUri; - - protected string $state; - - protected GrantFactory $grantFactory; - - protected ReuqestFactory $requestFactory; - - protected OptionProviderInterface $optionProvider; - - public function __construct(array $options = [], array $collaborators = []) - { - foreach ($options as $key => $option) { - if (\property_exists($this, $key)) { - $this->{$key} = $option; - } - } - - $this->setGrantFactory($collaborators['grantFactory'] ?? new GrantFactory()); - $this->setRequestFactory($collaborators['requestFactory'] ?? new RequestFactory()); - $this->setOptionProvider($collaborators['optionProvider'] ?? new PostAuthOptionProvider()); - } - - public function setGrantFactory(GrantFactory $factory) : self - { - $this->grantFactory = $factory; - - return $this; - } - - public function getGrantFactory() : GrantFactory - { - return $this->grantFactory; - } - - public function setRequestFactory(RequestFactory $factory) : self - { - $this->requestFactory = $factory; - - return $this; - } - - public function getRequestFactory() : RequestFactory - { - return $this->requestFactory; - } - - public function setOptionProvider(OptionProviderInterface $provider) : self - { - $this->optionProvider = $provider; - - return $this; - } - - public function getOptionProvider() : OptionProviderInterface - { - return $this->optionProvider; - } - - public function getState() : string - { - return $this->state; - } - - abstract public function getBaseAuthorizationUrl() : string; - - abstract public function getBaseAccessTokenUrl(array $params = []) : string; - - abstract public function getResourceOwnerDetailsUrl(AccessToken $token) : string; - - protected function getRandomState(int $length = 32) : string - { - return \bin2hex(\random_bytes($length / 2)); - } - - abstract protected function getDefaultScopes() : array; - - protected function getScopeSeparator() : string - { - return ','; - } - - protected function getAuthorizationParameters(array $options) : array - { - $options['state'] ??= $this->getRandomState(); - $options['scope'] ??= $this->getDefaultScopes(); - - $this->state = $options['state']; - - $options += [ - 'response_type' => 'code', - 'approval_prompt' => 'auto', - ]; - - if (\is_array($options['scope'])) { - $options['scope'] = \implode($this->getScopeSeparator(), $options['scope']); - } - - $options['redirect_uri'] ??= $this->redirectUri; - $options['client_id'] = $this->clientId; - - return $options; - } - - protected function getAuthorizationQuery(array $params) : string - { - return \http_build_query($params, '', '&', \PHP_QUERY_RFC3986); - } - - public function getauthorizationUrl(array $options = []) : string - { - $base = $this->getBaseAuthorizationUrl(); - $params = $this->getAuthorizationParameters($options); - $query = $this->getAuthorizationQuery($params); - - return UriFactory::build($base . '?' . $query); - } - - public function authorize(array $options = [], callable $redirectHandler = null) - { - $url = $this->getAuthorizationUrl($options); - if ($redirectHandler !== null) { - return $redirectHandler($url, $this); - } - - // @codeCoverageIgnoreStart - \header('Location: ' . $url); - exit; - // @codeCoverageIgnoreEnd - } - - protected function getAccessTokenMethod() : string - { - return RequestMethod::POST; - } - - protected function getAccessTokenResourceOwnerId() : ?string - { - return static::ACCESS_TOKEN_RESOURCE_OWNER_ID; - } - - protected function getAccessTokenUrl(array $params) : string - { - $url = $this->getBaseAccessTokenUrl($params); - - if ($this->getAccessTokenMethod() === RequestMethod::GET) { - $query = \http_build_query($params, '', '&', \PHP_QUERY_RFC3986); - - return UriFactory::build($url . '?' . $query); - } - - return $url; - } - - protected function getAccessTokenRequest(array $params) : HttpRequest - { - $method = $this->getAccessTokenMethod(); - $url = $this->getAccessTokenUrl($params); - $options = $this->getoptionProvider->getAccessTokenOptions($this->getAccessTokenMethod(), $params); - - return $this->createRequest($method, $url, null, $options); - } - - // string | Grant - public function getAccessToken($grant, array $options = []) : AccessTokenInterface - { - $grant = \is_string($grant) ? $this->grantFactory->getGrant($grant) : $grant; - - $params = [ - 'client_id' => $this->clientId, - 'client_secret' => $this->clientSecret, - 'redirect_uri' => $this->redirectUri, - ]; - - $params = $grant->prepareRequestParameters($params, $options); - $request = $this->getAccessTokenRequest($params); - $response = $this->getParsedResponse($request); - - $prepared = $this->prepareAccessTokenResponse($response); - $token = $this->createAccessToken($prepared, $grant); - - return $token; - } - - public function createRequest(string $method, string $url, $token, array $options) : HttpRequest - { - $defaults = [ - 'headers' => $this->getHeaders($token), - ]; - - $options = \array_merge_recursive($defaults, $options); - $factory = $this->getRequestFactory(); - - return $factory->getRequestWithOptions($method, $url, $options); - } - - public function getParsedResponse(HttpRequest $request) - { - $response = $request->rest(); - $parsed = $this->parseResponse($response); - - return $parsed; - } - - protected function parseResponse(HttpResponse $response) : array - { - $content = $response->getBody(); - $type = \implode(';', (array) $response->header->get('Content-Type')); - - if (\stripos($type, 'urlencoded') !== false) { - \parse_str($content, $parsed); - - return $parsed; - } - - try { - return \json_decode($content, true); - } catch (\Throwable $t) { - return []; - } - } - - // todo: consider to make bool - - protected function prepareAccessTokenResponse(array $result) : array - { - if (($id = $this->getAccesstokenResourceOwnerId()) !== null) { - $result['resource_owner_id'] = ArrayUtils::getArray($id, $result, '.'); - } - - return $result; - } - - protected function createAccessToken(array $response, GrantAbstract $grant) : AccessTokenInterface - { - return new AccessToken($response); - } - - abstract protected function createResourceOwner(array $response, AccessToken $token) : ResourceOwnerInterface; - - public function getResourceOwner(AccessToken $token) : ResourceOwnerInterface - { - $response = $this->fetchResourceOwnerDetails($token); - - return $this->createResourceOwner($response, $token); - } - - protected function fetchResourceOwnerDetails(AccessToken $token) - { - $url = $this->getResourceOwnerDetailsUrl($token); - $request = $this->createRequest(RequestMethod::GET, $url, $token, []); - $response = $this->getParsedResponse($request); - - return $response; - } - - protected function getDefaultHeaders() : array - { - return []; - } - - protected function getAuthorizationHeaders($token = null) : array - { - return []; - } - - public function getHeaders($token = null) : array - { - return $token === null - ? $this->getDefaultHeaders() - : \array_merge($this->getDefaultHeaders(), $this->getAuthorizationHeaders()); - } -} diff --git a/Auth/OAuth2/Provider/ResourceOwnerInterface.php b/Auth/OAuth2/Provider/ResourceOwnerInterface.php deleted file mode 100644 index ced7a8eba..000000000 --- a/Auth/OAuth2/Provider/ResourceOwnerInterface.php +++ /dev/null @@ -1,46 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Provider; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Provider - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -interface ResourceOwnerInterface -{ - /** - * Get id - * - * @return string - * - * @since 1.0.0 - */ - public function getId() : string; - - /** - * Serialize as array - * - * @return array - * - * @since 1.0.0 - */ - public function toArray() : array; -} diff --git a/Auth/OAuth2/Token/AccessToken.php b/Auth/OAuth2/Token/AccessToken.php deleted file mode 100644 index 7d8e55efd..000000000 --- a/Auth/OAuth2/Token/AccessToken.php +++ /dev/null @@ -1,123 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Token; - -/** - * Access token class. - * - * @package phpOMS\Auth\OAuth2\Token - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface -{ - protected string $accessToken; - - protected int $expires = -1; - - protected ?string $refreshToken = null; - - protected ?string $resourceOwnerId = null; - - protected array $values = []; - - public function __construct(array $options = []) - { - if (!isset($options['access_token'])) { - throw new \InvalidArgumentException(); - } - - $this->accessToken = $options['access_token']; - - if (isset($options['resource_owner_id'])) { - $this->resourceOwnerId = $options['resource_owner_id']; - } - - if (isset($options['refresh_token'])) { - $this->refreshToken = $options['refresh_token']; - } - - if (isset($options['expires_in'])) { - $this->expires = $options['expires_in'] !== 0 ? \time() + $options['expires_in'] : 0; - } elseif (!empty($options['expires'])) { - $this->expires = $options['expires']; - } - - $this->values = \array_diff_key($options, \array_flip([ - 'access_token', - 'resource_owner_id', - 'refresh_token', - 'expires_in', - 'expires', - ])); - } - - public function getToken() : string - { - return $this->accessToken; - } - - public function getExpires() : int - { - return $this->expires; - } - - public function getRefreshToken() : ?string - { - return $this->refreshToken; - } - - public function getResourceOwnerId() : ?string - { - return $this->resourceOwnerId; - } - - public function hasExpired() : bool - { - return $this->expires > 0 && $this->expires < \time(); - } - - public function getValues() : array - { - return $this->values; - } - - public function __toString() - { - return $this->getToken(); - } - - public function jsonSerialize() - { - $params = $this->values; - $params['access_token'] = $this->accessToken; - - if ($this->refreshToken !== null) { - $params['refresh_token'] = $this->refreshToken; - } - - if ($this->expires > 0) { - $params['expires'] = $this->expires; - } - - if ($this->resourceOwnerId !== null) { - $params['resource_owner_id'] = $this->resourceOwnerId; - } - - return $params; - } -} diff --git a/Auth/OAuth2/Token/AccessTokenInterface.php b/Auth/OAuth2/Token/AccessTokenInterface.php deleted file mode 100644 index 7b5e8ef76..000000000 --- a/Auth/OAuth2/Token/AccessTokenInterface.php +++ /dev/null @@ -1,42 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Token; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Token - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -interface AccessTokenInterface extends \JsonSerializable -{ - public function getToken() : string; - - public function getRefreshToken() : ?string; - - public function getExpires() : int; - - public function hasExpired() : bool; - - public function getValues() : array; - - public function __toString(); - - public function jsonSerialize(); -} diff --git a/Auth/OAuth2/Token/ResourceOwnerAccessTokenInterface.php b/Auth/OAuth2/Token/ResourceOwnerAccessTokenInterface.php deleted file mode 100644 index 3c288eac2..000000000 --- a/Auth/OAuth2/Token/ResourceOwnerAccessTokenInterface.php +++ /dev/null @@ -1,30 +0,0 @@ - - thephpleague/oauth2-client - * @license OMS License 1.0 - * @version 1.0.0 - * @link https://orange-management.org - * @see https://tools.ietf.org/html/rfc6749 - */ -declare(strict_types=1); - -namespace phpOMS\Auth\OAuth2\Token; - -/** - * Provider class. - * - * @package phpOMS\Auth\OAuth2\Token - * @license OMS License 1.0 - * @link https://orange-management.org - * @since 1.0.0 - */ -interface ResourceOwnerAccessTokenInterface extends AccessTokenInterface -{ - public function getResourceOwnerId() : ?string; -}