/** * @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; }
public function testErrorWhenNoTokenIsReturnedWillNotIntercept() { $handler = new MockHandler([function (RequestInterface $request) { $this->assertEquals('', $request->getHeaderLine('Authorization')); return new Response(401); }]); $this->grant->shouldReceive('getToken')->atLeast()->once()->andReturn(null); $stack = new HandlerStack($handler); $stack->push(OAuth2Middleware::middleware($this->grant)); $comp = $stack->resolve(); /** @var PromiseInterface $promise */ $promise = $comp(new Request('GET', 'https://example.com'), ['auth' => 'gigya-oauth2']); $this->assertInstanceOf(PromiseInterface::class, $promise); /** @var ResponseInterface $response */ $response = $promise->wait(true); $this->assertEquals(401, $response->getStatusCode()); }