diff options
Diffstat (limited to 'vendor/OAuth/OAuth2/Service/Harvest.php')
-rwxr-xr-x | vendor/OAuth/OAuth2/Service/Harvest.php | 84 |
1 files changed, 78 insertions, 6 deletions
diff --git a/vendor/OAuth/OAuth2/Service/Harvest.php b/vendor/OAuth/OAuth2/Service/Harvest.php index 86e8993c..96fb0f2d 100755 --- a/vendor/OAuth/OAuth2/Service/Harvest.php +++ b/vendor/OAuth/OAuth2/Service/Harvest.php @@ -2,13 +2,14 @@ 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\Exception\TokenResponseException; +use OAuth\Common\Http\Uri\Uri; use OAuth\Common\Http\Uri\UriInterface; +use OAuth\Common\Storage\TokenStorageInterface; +use OAuth\Common\Token\TokenInterface; +use OAuth\OAuth2\Token\StdOAuth2Token; class Harvest extends AbstractService { @@ -23,8 +24,32 @@ class Harvest extends AbstractService parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); if (null === $baseApiUri) { - $this->baseApiUri = new Uri('https://api.github.com/'); + $this->baseApiUri = new Uri('https://api.harvestapp.com/'); + } + } + + /** + * {@inheritdoc} + */ + public function getAuthorizationUri(array $additionalParameters = array()) + { + $parameters = array_merge( + $additionalParameters, + array( + 'client_id' => $this->credentials->getConsumerId(), + 'redirect_uri' => $this->credentials->getCallbackUrl(), + 'state' => 'optional-csrf-token', + 'response_type' => 'code', + ) + ); + + // Build the url + $url = clone $this->getAuthorizationEndpoint(); + foreach ($parameters as $key => $val) { + $url->addToQuery($key, $val); } + + return $url; } /** @@ -66,7 +91,8 @@ class Harvest extends AbstractService $token = new StdOAuth2Token(); $token->setAccessToken($data['access_token']); - $token->setEndOfLife($data['expires_in']); + $token->setLifetime($data['expires_in']); + $token->setRefreshToken($data['refresh_token']); unset($data['access_token']); @@ -76,10 +102,56 @@ class Harvest extends AbstractService } /** + * Refreshes an OAuth2 access token. + * + * @param TokenInterface $token + * + * @return TokenInterface $token + * + * @throws MissingRefreshTokenException + */ + 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( + $this->getAccessTokenEndpoint(), + $parameters, + $this->getExtraOAuthHeaders() + ); + $token = $this->parseAccessTokenResponse($responseBody); + $this->storage->storeAccessToken($this->service(), $token); + + return $token; + } + + /** * @return array */ protected function getExtraOAuthHeaders() { return array('Accept' => 'application/json'); } + + /** + * Return any additional headers always needed for this service implementation's API calls. + * + * @return array + */ + protected function getExtraApiHeaders() + { + return array('Accept' => 'application/json'); + } } |