From 0081579882e00e0722e4467f9b6a9533ceeac5ce Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Tue, 22 Aug 2017 17:10:15 +0200 Subject: [PATCH] Remove Parrot Flower Power Oauth api is no longer available. :( --- README.md | 1 - examples/init.example.php | 4 - examples/parrotFlowerPower.php | 52 ------ .../OAuth2/Service/ParrotFlowerPower.php | 142 --------------- .../OAuth2/Service/ParrotFlowerPowerTest.php | 165 ------------------ 5 files changed, 364 deletions(-) delete mode 100644 examples/parrotFlowerPower.php delete mode 100644 src/OAuth/OAuth2/Service/ParrotFlowerPower.php delete mode 100644 tests/Unit/OAuth2/Service/ParrotFlowerPowerTest.php diff --git a/README.md b/README.md index 2eebab78..f0f764ab 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,6 @@ Included service implementations - Mondo - Nest - Netatmo - - Parrot Flower Power - PayPal - Pinterest - Pocket diff --git a/examples/init.example.php b/examples/init.example.php index 6ab1cdb0..670917ae 100644 --- a/examples/init.example.php +++ b/examples/init.example.php @@ -131,10 +131,6 @@ 'key' => '', 'secret' => '', ), - 'parrotFlowerPower' => array( - 'key' => '', - 'secret' => '', - ), 'paypal' => array( 'key' => '', 'secret' => '', diff --git a/examples/parrotFlowerPower.php b/examples/parrotFlowerPower.php deleted file mode 100644 index d58c3471..00000000 --- a/examples/parrotFlowerPower.php +++ /dev/null @@ -1,52 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki - */ - -use OAuth\OAuth2\Service\ParrotFlowerPower; -use OAuth\Common\Storage\Session; -use OAuth\Common\Consumer\Credentials; -use OAuth\Common\Http\Client\CurlClient; - -/** - * Bootstrap the example - */ -require_once __DIR__ . '/bootstrap.php'; - -// Session storage -$storage = new Session(); - -// Setup the credentials for the requests -$credentials = new Credentials( - $servicesCredentials['parrotFlowerPower']['key'], - $servicesCredentials['parrotFlowerPower']['secret'], - $currentUri->getAbsoluteUri() -); - -$serviceFactory->setHttpClient(new CurlClient); - -// Instantiate the ParrotFlowerPower service using the credentials, http client and storage mechanism for the token -$parrotFlowerPowerService = $serviceFactory->createService('parrotFlowerPower', $credentials, $storage); - -if (!empty($_GET['code'])) { - // This was a callback request from parrotFlowerPower, get the token - $token = $parrotFlowerPowerService->requestAccessToken($_GET['code']); - // Send a request with it - $result = json_decode($parrotFlowerPowerService->request('https://apiflowerpower.parrot.com/user/v4/profile'), true); - // Show some of the resultant data - echo 'Hello '.$result['user_profile']['username'].' '.$result['user_profile']['email']; - -} elseif (!empty($_GET['go']) && $_GET['go'] === 'go') { - $url = $parrotFlowerPowerService->getAuthorizationUri(); - header('Location: ' . $url); -} else { - $url = $currentUri->getRelativeUri() . '?go=go'; - echo "Login with ParrotFlowerPower!"; -} diff --git a/src/OAuth/OAuth2/Service/ParrotFlowerPower.php b/src/OAuth/OAuth2/Service/ParrotFlowerPower.php deleted file mode 100644 index 78ef9425..00000000 --- a/src/OAuth/OAuth2/Service/ParrotFlowerPower.php +++ /dev/null @@ -1,142 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki - */ - -namespace OAuth\OAuth2\Service; - -use OAuth\OAuth2\Token\StdOAuth2Token; -use OAuth\Common\Http\Exception\TokenResponseException; -use OAuth\Common\Http\Uri\Uri; -use OAuth\Common\Consumer\CredentialsInterface; -use OAuth\Common\Http\Client\ClientInterface; -use OAuth\Common\Storage\TokenStorageInterface; -use OAuth\Common\Http\Uri\UriInterface; -use OAuth\OAuth2\Service\Exception\MissingRefreshTokenException; -use OAuth\Common\Token\TokenInterface; - -/** - * ParrotFlowerPower service. - * - * @author Pedro Amorim - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @link https://flowerpowerdev.parrot.com/projects/flower-power-web-service-api/wiki - */ -class ParrotFlowerPower extends AbstractService -{ - - public function __construct( - CredentialsInterface $credentials, - ClientInterface $httpClient, - TokenStorageInterface $storage, - $scopes = array(), - UriInterface $baseApiUri = null - ) { - parent::__construct( - $credentials, - $httpClient, - $storage, - $scopes, - $baseApiUri, - true - ); - - if (null === $baseApiUri) { - $this->baseApiUri = new Uri('https://apiflowerpower.parrot.com/'); - } - } - - /** - * {@inheritdoc} - */ - public function getAuthorizationEndpoint() - { - return new Uri($this->baseApiUri.'oauth2/v1/authorize'); - - } - - /** - * {@inheritdoc} - */ - public function getAccessTokenEndpoint() - { - return new Uri($this->baseApiUri.'user/v1/authenticate'); - } - - /** - * {@inheritdoc} - */ - protected function getAuthorizationMethod() - { - return static::AUTHORIZATION_METHOD_HEADER_BEARER; - } - - /** - * {@inheritdoc} - */ - protected function parseAccessTokenResponse($responseBody) - { - $data = json_decode($responseBody, true); - - if (null === $data || !is_array($data)) { - throw new TokenResponseException('Unable to parse response.'); - } elseif (isset($data['error'])) { - throw new TokenResponseException( - 'Error in retrieving token: "' . $data['error'] . '"' - ); - } - - $token = new StdOAuth2Token(); - $token->setAccessToken($data['access_token']); - $token->setLifetime($data['expires_in']); - - if (isset($data['refresh_token'])) { - $token->setRefreshToken($data['refresh_token']); - unset($data['refresh_token']); - } - - unset($data['access_token']); - unset($data['expires_in']); - - $token->setExtraParams($data); - - return $token; - } - - - /** - * Parrot use a different endpoint for refresh a token - * - * {@inheritdoc} - */ - public function refreshAccessToken(TokenInterface $token) - { - $refreshToken = $token->getRefreshToken(); - - if (empty($refreshToken)) { - throw new MissingRefreshTokenException(); - } - - $parameters = array( - 'grant_type' => 'refresh_token', - 'type' => 'web_server', - 'client_id' => $this->credentials->getConsumerId(), - 'client_secret' => $this->credentials->getConsumerSecret(), - 'refresh_token' => $refreshToken, - ); - - $responseBody = $this->httpClient->retrieveResponse( - new Uri($this->baseApiUri.'user/v1/refresh'), - $parameters, - $this->getExtraOAuthHeaders() - ); - $token = $this->parseAccessTokenResponse($responseBody); - $this->storage->storeAccessToken($this->service(), $token); - - return $token; - } -} diff --git a/tests/Unit/OAuth2/Service/ParrotFlowerPowerTest.php b/tests/Unit/OAuth2/Service/ParrotFlowerPowerTest.php deleted file mode 100644 index 5a1e2940..00000000 --- a/tests/Unit/OAuth2/Service/ParrotFlowerPowerTest.php +++ /dev/null @@ -1,165 +0,0 @@ -getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - */ - public function testConstructCorrectInstanceWithoutCustomUri() - { - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - */ - public function testConstructCorrectInstanceWithCustomUri() - { - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), - array(), - $this->getMock('\\OAuth\\Common\\Http\\Uri\\UriInterface') - ); - - $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\AbstractService', $service); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::getAuthorizationEndpoint - */ - public function testGetAuthorizationEndpoint() - { - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertSame( - 'https://apiflowerpower.parrot.com/oauth2/v1/authorize', - $service->getAuthorizationEndpoint()->getAbsoluteUri() - ); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::getAccessTokenEndpoint - */ - public function testGetAccessTokenEndpoint() - { - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'), - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertSame( - 'https://apiflowerpower.parrot.com/user/v1/authenticate', - $service->getAccessTokenEndpoint()->getAbsoluteUri() - ); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::parseAccessTokenResponse - */ - public function testParseAccessTokenResponseThrowsExceptionOnNulledResponse() - { - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); - $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue(null)); - - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $client, - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); - - $service->requestAccessToken('foo'); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::parseAccessTokenResponse - */ - public function testParseAccessTokenResponseThrowsExceptionOnError() - { - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); - $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('error=some_error')); - - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $client, - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->setExpectedException('\\OAuth\\Common\\Http\\Exception\\TokenResponseException'); - - $service->requestAccessToken('foo'); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::parseAccessTokenResponse - */ - public function testParseAccessTokenResponseValidWithoutRefreshToken() - { - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); - $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar"}')); - - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $client, - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); - } - - /** - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::__construct - * @covers OAuth\OAuth2\Service\ParrotFlowerPower::parseAccessTokenResponse - */ - public function testParseAccessTokenResponseValidWithRefreshToken() - { - $client = $this->getMock('\\OAuth\\Common\\Http\\Client\\ClientInterface'); - $client->expects($this->once())->method('retrieveResponse')->will($this->returnValue('{"access_token":"foo","expires_in":"bar","refresh_token":"baz"}')); - - $service = new ParrotFlowerPower( - $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), - $client, - $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface') - ); - - $this->assertInstanceOf('\\OAuth\\OAuth2\\Token\\StdOAuth2Token', $service->requestAccessToken('foo')); - } -}