示例#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);
     }
 }
示例#2
0
 function it_can_authorize_the_client(HttpAdapter $httpAdapter)
 {
     $response = ['access_token' => 'myapitoken', 'expires_in' => 3600, 'token_type' => 'bearer', 'scope' => ''];
     $httpAdapter->post('oauth/token', ['client_id' => 'myid', 'client_secret' => 'mysecret', 'grant_type' => 'client_credentials'], [], HttpAdapter::RETURN_TYPE_JSON)->willReturn($response);
     $httpAdapter->getResponseCode()->willReturn(200);
     $httpAdapter->get('documents', ['access_token' => 'myapitoken'], [], HttpAdapter::RETURN_TYPE_JSON)->willReturn([]);
     $this->getDocuments();
 }