コード例 #1
0
ファイル: Client.php プロジェクト: wadify/wadify-sdk-php
 /**
  * @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));
 }
コード例 #2
0
 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());
 }
コード例 #3
0
 /**
  * Create a new Oauth2 subscriber.
  *
  * @param ClientInterface                     $client
  * @param GrantTypeInterface|null             $grantType
  * @param RefreshTokenGrantTypeInterface|null $refreshTokenGrantType
  * @param array                               $options
  */
 public function __construct(ClientInterface $client, GrantTypeInterface $grantType = null, RefreshTokenGrantTypeInterface $refreshTokenGrantType = null, array $options = [])
 {
     parent::__construct($client, $grantType, $refreshTokenGrantType);
     $this->options = $options;
     $this->tokenExpiredOnFailureCount = 0;
 }