public function register(Application $app)
 {
     $app['soauth.test'] = false;
     $app['security.authentication_listener.factory.soauth'] = $app->protect(function ($name, $options) use($app) {
         $app['security.authentication_provider.' . $name . '.soauth'] = $app->share(function () use($app, $name) {
             return null;
         });
         $app['security.authentication_listener.' . $name . '.soauth'] = $app->share(function () use($app, $name) {
             $listener = new Listener($name, $app['security'], $app['soauth.access.provider']);
             if (isset($app['logger']) && $app['logger']) {
                 $listener->setLogger($app['logger']);
             }
             return $listener;
         });
         return array('security.authentication_provider.' . $name . '.soauth', 'security.authentication_listener.' . $name . '.soauth', null, 'pre_auth');
     });
     $app['soauth.access.provider'] = $app->share(function (Application $app) {
         $accessProvider = new AccessProvider($app['soauth.test'] ? $app['soauth.storage.handler.mock'] : $app['soauth.storage.handler'], $app['soauth.client.provider'], $app['soauth.user.provider']);
         if (isset($app['logger']) && $app['logger']) {
             $accessProvider->setLogger($app['logger']);
         }
         return $accessProvider;
     });
     $app['soauth.storage.handler.mock'] = $app->share(function (Application $app) {
         return new MockStorageHandler();
     });
     $app['soauth.client.provider'] = $app->share(function (Application $app) {
         return new ClientProvider($app['soauth.client.provider.config']);
     });
     $app['soauth.user.provider'] = $app->share(function (Application $app) {
         return new UserProvider($app['soauth.user.provider.config']);
     });
     $app['soauth.user.provider.config'] = [];
     $app['soauth.client.provider.config'] = [];
 }
예제 #2
0
 /**
  * @expectedException Renegare\Soauth\SoauthException
  */
 public function testGenerateInvalidClientException()
 {
     $mockStorage = new MockStorageHandler();
     $mockClientProvider = $this->getMock('Renegare\\Soauth\\ClientProviderInterface');
     $mockUserProvider = $this->getMock('Renegare\\Soauth\\UserProviderInterface');
     $mockRequest = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $mockUserProvider->expects($this->any())->method('getUser')->will($this->returnValue($this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface')));
     $mockUserProvider->expects($this->any())->method('isValid')->will($this->returnValue(true));
     $mockClient = $this->getMock('Renegare\\Soauth\\ClientInterface');
     $mockClientProvider->expects($this->once())->method('getClient')->will($this->returnCallback(function ($id) use($mockClient) {
         $this->assertEquals(1, $id);
         return $mockClient;
     }));
     $mockClientProvider->expects($this->once())->method('isValid')->will($this->returnCallback(function ($client) use($mockClient) {
         $this->assertSame($mockClient, $client);
         return false;
     }));
     $accessProvider = new AccessProvider($mockStorage, $mockClientProvider, $mockUserProvider);
     $accessProvider->generate($mockRequest, 1, '...', 'user...');
 }