public function createDelegatorWithName(ServiceLocatorInterface $services, $name, $requestedName, $callback) { /*@var DefaultAuthenticationListener $listener*/ $listener = $callback(); $config = $services->get('Config'); if (!isset($config['zf-mvc-auth']['authentication']['adapters']) || !is_array($config['zf-mvc-auth']['authentication']['adapters'])) { return $listener; } foreach ($config['zf-mvc-auth']['authentication']['adapters'] as $type => $data) { if (!isset($data['adapter']) || !is_string($data['adapter'])) { continue; } switch ($data['adapter']) { case 'Schmiddim\\MvcAuth\\Adapter\\ApiKeyAdapter': $adapter = AuthenticationApiKeyAdapterFactory::factory($type, $data, $services); break; case 'ZF\\MvcAuth\\Authentication\\HttpAdapter': $adapter = AuthenticationHttpAdapterFactory::factory($type, $data, $services); break; case 'ZF\\MvcAuth\\Authentication\\OAuth2Adapter': $adapter = AuthenticationOAuth2AdapterFactory::factory($type, $data, $services); break; default: $adapter = false; break; } if ($adapter) { $listener->attach($adapter); } } return $listener; }
public function testCreatesInstanceFromValidConfiguration() { $config = array( 'adapter' => 'pdo', 'storage' => array( 'adapter' => 'pdo', 'dsn' => 'sqlite::memory:', ), ); $this->services->expects($this->any()) ->method('get') ->with($this->stringContains('Config')) ->will($this->returnValue(array( 'zf-oauth2' => array( 'grant_types' => array( 'client_credentials' => true, 'authorization_code' => true, 'password' => true, 'refresh_token' => true, 'jwt' => true, ), 'api_problem_error_response' => true, ), ))); $adapter = AuthenticationOAuth2AdapterFactory::factory('foo', $config, $this->services); $this->assertInstanceOf('ZF\MvcAuth\Authentication\OAuth2Adapter', $adapter); $this->assertEquals(array('foo'), $adapter->provides()); }
/** * Attach an adaper to the listener as described by $type and $data. * * @param string $type * @param array $adapterConfig * @param ContainerInterface $container * @param DefaultAuthenticationListener $listener */ private function attachAdapterOfType($type, array $adapterConfig, ContainerInterface $container, DefaultAuthenticationListener $listener) { if (!isset($adapterConfig['adapter']) || !is_string($adapterConfig['adapter'])) { return; } switch ($adapterConfig['adapter']) { case HttpAdapter::class: $adapter = AuthenticationHttpAdapterFactory::factory($type, $adapterConfig, $container); break; case OAuth2Adapter::class: $adapter = AuthenticationOAuth2AdapterFactory::factory($type, $adapterConfig, $container); break; default: $adapter = false; break; } if (!$adapter) { return; } $listener->attach($adapter); }