From 361c026ec1cc56dca9ff2f0e3b0a89c8ee44f74b Mon Sep 17 00:00:00 2001 From: Florin Popa Date: Mon, 14 Oct 2013 23:24:50 +0300 Subject: [PATCH] Updated the examples --- README.md | 10 +++++----- example/example.php | 28 +++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a6fec23..94367d8 100644 --- a/README.md +++ b/README.md @@ -16,21 +16,21 @@ ), ) ) - ); + ); // Enable extension $app->register(new OpauthExtension()); // Listen for events - $app->dispatcher->addListener(OpauthExtension::EVENT_ERROR, function($e) { + $app->on(OpauthExtension::EVENT_ERROR, function($e) { $this->log->error('Auth error: ' . $e['message'], ['response' => $e->getSubject()]); $e->setArgument('result', $this->redirect('/')); }); - $app->dispatcher->addListener(OpauthExtension::EVENT_SUCCESS, function($e) { + $app->on(OpauthExtension::EVENT_SUCCESS, function($e) { $response = $e->getSubject(); - /* + /* find/create a user, oauth response is in $response and it's already validated! store the user in the session */ @@ -69,7 +69,7 @@ To login using opauth use /login/PROVIDER, or use `opauth_default_login` route w ``` -By default, users will be looked up by username "provider:uid". +By default, users will be looked up by username "provider:uid". You should extend your user provider to handle OPauth results correctly by implementing `OpauthUserProviderInterface`. diff --git a/example/example.php b/example/example.php index 4c2bd08..5da4521 100644 --- a/example/example.php +++ b/example/example.php @@ -7,15 +7,17 @@ $app = new Application(); +$app['debug'] = true; + $app['opauth'] = array( - 'login' => '/auth/login', + 'login' => '/auth/login', // Generates a path /auth/login/{strategy} 'callback' => '/auth/callback', 'config' => array( - 'security_salt' => 'LDFmiilYf8Fyw5W10rxx4W1KsVrieQCnpBzzpTBWA5vJidQKDx8pMJbmw28R1C4m', + 'security_salt' => '_SECURE_RANDOM_SALT_', 'Strategy' => array( - 'Facebook' => array( + 'Facebook' => array( // Is available at /auth/login/facebook 'app_id' => 'APP_ID', - 'app_secret' => 'APP_SECRET' + 'app_secret' => 'APP_SECRETE' ), ) ) @@ -24,4 +26,20 @@ $app->register(new OpauthExtension()); -$app->run(); \ No newline at end of file +// Listen for events +$app->on(OpauthExtension::EVENT_ERROR, function($e) { + $this->log->error('Auth error: ' . $e['message'], ['response' => $e->getSubject()]); + $e->setArgument('result', $this->redirect('/')); +}); + +$app->on(OpauthExtension::EVENT_SUCCESS, function($e) { + $response = $e->getSubject(); + + /* + find/create a user, oauth response is in $response and it's already validated! + store the user in the session + */ + + $e->setArgument('result', $this->redirect('/')); +}); +$app->run();