public function testSubscriberDoesNotDoAnythingForNonGigyaAuthRequests()
 {
     $handler = new MockHandler([function (RequestInterface $request) {
         $query = $request->getUri()->getQuery();
         $this->assertNotRegExp('/client_id=/', $query);
         $this->assertNotRegExp('/client_secret=/', $query);
         return new Response(200);
     }]);
     $stack = new HandlerStack($handler);
     $stack->push(CredentialsAuthMiddleware::middleware('key', 'secret', 'user'));
     $comp = $stack->resolve();
     $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'oauth']);
     $this->assertInstanceOf(PromiseInterface::class, $promise);
 }
示例#2
0
 /**
  * @param string      $apiKey
  * @param string      $secretKey
  * @param string|null $dataCenter
  * @param string|null $userKey
  * @param array       $config     Gigya configuration:
  *                                - auth <string> (Default: gigya) Type of authentication, gigya
  *                                (HttpsAuthMiddleware) is the default. 'credentials' provides
  *                                `client_id,client_secret` params, 'gigya-oauth2' uses an oauth2 access token
  *                                - uidValidator <bool> (Default: true) Include Uid Signature Validation
  *                                - factory <object> (Default: null) A ResponseFactoryInterface to use, if none is
  *                                provided ResponseFactory will be used
  *                                - guzzle <array> (Default: []) A configuration to pass to guzzle if required
  *                                - options <array> (Default: []) A set of options to pass to each request
  */
 public function __construct($apiKey, $secretKey, $dataCenter = null, $userKey = null, array $config = [])
 {
     $guzzleConfig = isset($config['guzzle']) ? $config['guzzle'] : [];
     if (!isset($guzzleConfig['handler'])) {
         $guzzleConfig['handler'] = new HandlerStack(new CurlHandler());
     }
     $this->handlerStack = $guzzleConfig['handler'];
     $this->guzzle = new GuzzleClient($guzzleConfig);
     if (isset($config['options'])) {
         $this->addOptions($config['options']);
     }
     $this->addOption('verify', __DIR__ . '/' . static::CERTIFICATE_FILE);
     $this->addHandler(HttpsAuthMiddleware::middleware($apiKey, $secretKey, $userKey));
     $this->addHandler(CredentialsAuthMiddleware::middleware($apiKey, $secretKey, $userKey));
     $auth = isset($config['auth']) ? $config['auth'] : 'gigya';
     switch ($auth) {
         case 'gigya-oauth2':
             $this->addOption('auth', 'gigya-oauth2');
             $this->addHandler(OAuth2Middleware::middleware(new GigyaGrant($this)));
             break;
         default:
             $this->addOption('auth', $auth);
             break;
     }
     if (!isset($config['uidValidator']) || $config['uidValidator'] === true) {
         $this->addValidator(new UidSignatureValidator(new Signature(), $secretKey));
     }
     if (isset($config['factory'])) {
         $this->setFactory($config['factory']);
     }
     $this->dataCenter = $dataCenter ?: static::DC_EU;
 }