GromNaN / FacebookServiceProvider

Facebook API and connect integration into your Silex applications
MIT License
25 stars 6 forks source link

Services initialisation can provoke NotFoundHttpException or Redirect loop. #2

Closed jclaveau closed 10 years ago

jclaveau commented 11 years ago

``After loosing some hours, I finally pointed my issue : Depending on the way you initialize services, the FacebookServiceProvider won't work (Not Found or worse).

Here is my boostrap :

<?

ini_set("display_errors", 1);
error_reporting(E_ALL);

require_once 'helpers.php';

use Silex\Provider\SessionServiceProvider;
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\FacebookServiceProvider;
use Silex\Provider\SecurityServiceProvider;
use Silex\Provider\DoctrineServiceProvider;

$loader = require_once __DIR__.'/../vendor/autoload.php';
$loader->add( 'App', __DIR__ );
$app = new Silex\Application();

/// Conf
$app['debug'] = true;

$conf = array(
    'db'    => array(
        'db.options' => array(
            'driver'    => 'pdo_mysql',
            'host'      => 'localhost',
            'dbname'    => 'pouet',
            'user'      => 'plouf',
            'password'  => 'tagada',
            'charset'   => 'utf8',
        ),
    ),
    'fb'    => array(
        'facebook.config' => array(
            'appId'         => 'lalala',
            'secret'        => 'lololo',
        ),
        'facebook.permissions' => array('email'),
    ),
    'sec'   => array(
        'security.firewalls' => array(
            // 'admin' => array(
                // 'pattern'    => '^/admin',
                // 'http'       => array('real_name' => 'Admin'),
                // 'users'      => array(
                    // 'admin' => array('ROLE_ADMIN', 'tsointsoin'),
                // ),
                // 'users' => $app->share(function( $app ) {
                    // return new TM\User\UserProvider( $app );
                // }),
            // ),
            'public' => array(
                'pattern' => '^/',
                'facebook' => array(
                    'check_path' => '/login_check',
                ),
                'users' => $app->share(function () use ($app) {
                    return new App\FacebookUserProvider( $app['db'] );
                }),
            ),
        ),
    ),
);

/// Services
/**/
if( true ){
    $app->register( new DoctrineServiceProvider(), $conf['db'] );
    $app->register( new SessionServiceProvider() );
    $app->register( new SecurityServiceProvider() );
    $app->register( new FacebookServiceProvider() );
    // $app->register( new UrlGeneratorServiceProvider() );

    $app['facebook.config']     = $conf['fb']['facebook.config'];
    $app['security.firewalls']  = $conf['sec']['security.firewalls'];

} else { /**/

    $app->register( new DoctrineServiceProvider(), $conf['db'] );
    $app->register( new SessionServiceProvider() );
    $app->register( new FacebookServiceProvider(), $conf['fb'] );
    $app->register( new SecurityServiceProvider(), $conf['sec'] );
}

/// Controlleurs
$app->mount( '/', new App\Page() );
$app->mount( '/admin', new App\Admin() );

$app->run();
/**/

I've added an "if( true )" toggler to change the way the services are initialized. The first case works fine, the second one doesn't : loadUserByUsername is never called and I get a NotFoundHttpException on /login_check.

In both cases, if y don't specify any check_path, I get a redirect loop between my app and oauth.

As I'm absolutely not able to solve it, I hope my so-called diagnosis will help you.

Anyway, thanks a lot.

GromNaN commented 11 years ago

/login_check must be publicly accessible. Try adding 'anonymous' => true to the firewall.