Exemple #1
0
 /**
  * @return string
  */
 public function authorize()
 {
     $response = $this->http->post('oauth/token', ['client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'client_credentials'], [], HttpAdapter::RETURN_TYPE_JSON);
     $code = $this->http->getResponseCode();
     if ($code == 200 && array_key_exists('access_token', $response)) {
         return $response['access_token'];
     } else {
         throw new HttpException("No access token was provided in the response", $code);
     }
 }
Exemple #2
0
 function it_throws_exception_if_cache_cant_be_cleared(HttpAdapter $httpAdapter, Cache $cache)
 {
     $this->setOptions(['token_refresh' => false]);
     $cache->contains('token')->willReturn(true);
     $cache->fetch('token')->willReturn('expiredtoken');
     $httpAdapter->get('documents', ['access_token' => 'expiredtoken'], [], HttpAdapter::RETURN_TYPE_JSON)->willThrow(new TokenExpiredException("The access token provided has expired."));
     $cache->delete('token')->willReturn(false);
     $this->shouldThrow(new CacheException('Could not delete the key in the cache. Do you have permission?'))->duringGetDocuments();
 }