Exemplo n.º 1
0
 /**
  * @param array        $options
  * @param HandlerStack $stack
  */
 private function pushStack($options, $stack)
 {
     $options = [ApiKey::CONFIG_APIKEY => $options['apiKey'], ApiKey::CONFIG_CLIENT_ID => $options['clientId'], ApiKey::CONFIG_CLIENT_SECRET => $options['clientSecret'], ApiKey::CONFIG_TOKEN_URL => '/oauth/v2/token', ApiKey::CONFIG_AUTH_LOCATION => RequestOptions::BODY];
     $token = new ApiKey($this->client, $options);
     $refreshToken = new RefreshToken($this->client, $options);
     $this->middleware = new OAuthMiddleware($this->client, $token, $refreshToken);
     try {
         $token = $this->tokenStorageProvider->get();
         $this->middleware->setAccessToken($token->getAccessToken(), null, $token->getExpires());
         $this->middleware->setRefreshToken($token->getRefreshToken());
     } catch (TokenNotFoundException $e) {
     }
     $stack->push($this->middleware->onBefore());
     $stack->push($this->middleware->onFailure(5));
 }
 public function testSettingManualRefreshToken()
 {
     $client = $this->createClient([], []);
     $middleware = new OAuthMiddleware($client);
     $token = new AccessToken('token', 'client_credentials', ['refresh_token' => 'refreshTokenOld']);
     $middleware->setAccessToken($token);
     $this->assertEquals('refreshTokenOld', $middleware->getRefreshToken()->getToken());
     $middleware->setRefreshToken('refreshToken');
     $this->assertEquals('refresh_token', $middleware->getRefreshToken()->getType());
     $this->assertEquals('refreshToken', $middleware->getRefreshToken()->getToken());
 }