-
-
Save anonymous/f31a187ad6545db79ae1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imports: | |
- { resource: parameters.ini } | |
- { resource: security.yml } | |
framework: | |
#esi: ~ | |
translator: ~ | |
secret: %secret% | |
charset: UTF-8 | |
router: { resource: "%kernel.root_dir%/config/routing.yml" } | |
form: true | |
csrf_protection: true | |
validation: { enable_annotations: true } | |
templating: { engines: ['twig'] } #assets_version: SomeVersionScheme | |
session: | |
default_locale: %locale% | |
auto_start: true | |
# Twig Configuration | |
twig: | |
debug: %kernel.debug% | |
strict_variables: %kernel.debug% | |
# Assetic Configuration | |
assetic: | |
debug: %kernel.debug% | |
use_controller: false | |
# java: /usr/bin/java | |
filters: | |
cssrewrite: ~ | |
# closure: | |
# jar: %kernel.root_dir%/java/compiler.jar | |
# yui_css: | |
# jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar | |
# Doctrine Configuration | |
doctrine: | |
dbal: | |
driver: %database_driver% | |
host: %database_host% | |
port: %database_port% | |
dbname: %database_name% | |
user: %database_user% | |
password: %database_password% | |
charset: UTF8 | |
orm: | |
auto_generate_proxy_classes: %kernel.debug% | |
auto_mapping: true | |
# Swiftmailer Configuration | |
swiftmailer: | |
jms_security_extra: | |
secure_controllers: true | |
secure_all_services: false | |
fos_user: | |
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' | |
firewall_name: main | |
user_class: Acme\UserBundle\Entity\User | |
registration: | |
confirmation: | |
enabled: true | |
from_email: | |
address: noreply@acmedemo.com | |
sender_name: Acme Demo App | |
service: | |
mailer: fos_user.mailer.twig_swift | |
resetting: | |
email: | |
template: AcmeDemoBundle:User:resetting.email.twig | |
fos_facebook: | |
file: %kernel.root_dir%/../vendor/facebook/src/base_facebook.php | |
alias: facebook | |
app_id: 312766692113940 | |
secret: 7f4ddbf71155b0c045735f93c6164394 | |
cookie: true | |
permissions: [email, user_birthday, user_location] | |
services: | |
my.facebook.user: | |
class: Acme\UserBundle\Security\Provider\FacebookProvider | |
arguments: | |
facebook: "@fos_facebook.api" | |
userManager: "@fos_user.user_manager" | |
validator: "@validator" | |
container: "@service_container" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imports: | |
- { resource: config.yml } | |
framework: | |
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" } | |
profiler: { only_exceptions: false } | |
web_profiler: | |
toolbar: true | |
intercept_redirects: false | |
monolog: | |
handlers: | |
main: | |
type: stream | |
path: %kernel.logs_dir%/%kernel.environment%.log | |
level: debug | |
firephp: | |
type: firephp | |
level: info | |
assetic: | |
use_controller: true | |
security: | |
firewalls: | |
public: | |
fos_facebook: | |
app_url: "http://apps.facebook.com/speeddator/" | |
server_url: "http://localhost/facebookApp/app_dev.php/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\UserBundle\Security\Provider; | |
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; | |
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; | |
use Symfony\Component\Security\Core\User\UserProviderInterface; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
use \BaseFacebook; | |
use \FacebookApiException; | |
class FacebookProvider implements UserProviderInterface | |
{ | |
/** | |
* @var \Facebook | |
*/ | |
protected $facebook; | |
protected $userManager; | |
protected $validator; | |
public function __construct(BaseFacebook $facebook, $userManager, $validator) | |
{ | |
$this->facebook = $facebook; | |
$this->userManager = $userManager; | |
$this->validator = $validator; | |
} | |
public function supportsClass($class) | |
{ | |
return $this->userManager->supportsClass($class); | |
} | |
public function findUserByFbId($fbId) | |
{ | |
return $this->userManager->findUserBy(array('facebookID' => $fbId)); | |
} | |
public function loadUserByUsername($username) | |
{ | |
$user = $this->findUserByFbId($username); | |
try { | |
$fbdata = $this->facebook->api('/me'); | |
} catch (FacebookApiException $e) { | |
$fbdata = null; | |
} | |
if (!empty($fbdata)) { | |
if (empty($user)) { | |
$user = $this->userManager->createUser(); | |
$user->setEnabled(true); | |
$user->setPassword(''); | |
$user->setAlgorithm(''); | |
} | |
// TODO use http://developers.facebook.com/docs/api/realtime | |
$user->setFBData($fbdata); | |
if (count($this->validator->validate($user, 'Facebook'))) { | |
// TODO: the user was found obviously, but doesnt match our expectations, do something smart | |
throw new UsernameNotFoundException('The facebook user could not be stored'); | |
} | |
$this->userManager->updateUser($user); | |
} | |
if (empty($user)) { | |
throw new UsernameNotFoundException('The user is not authenticated on facebook'); | |
} | |
return $user; | |
} | |
public function refreshUser(UserInterface $user) | |
{ | |
if (!$this->supportsClass(get_class($user)) || !$user->getFacebookId()) { | |
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); | |
} | |
return $this->loadUserByUsername($user->getFacebookId()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns:fb="http://www.facebook.com/2008/fbml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<link rel="stylesheet" href="{{ asset('bundles/acmedemo/css/demo.css') }}" type="text/css" media="all" /> | |
<title>{% block title %}Demo Bundle{% endblock %}</title> | |
<link rel="shortcut icon" href="{{ asset('favicon.ico') }}" /> | |
</head> | |
<body> | |
{{ facebook_initialize({'xfbml': true, 'fbAsyncInit': 'onFbInit();'}) }} | |
{{ facebook_login_button({'autologoutlink': true}) }} | |
<script> | |
function goLogIn(){ | |
window.location.href = "{{ path('_security_check') }}"; | |
} | |
function onFbInit() { | |
if (typeof(FB) != 'undefined' && FB != null ) { | |
FB.Event.subscribe('auth.statusChange', function(response) { | |
if (response.session || response.authResponse) { | |
setTimeout(goLogIn, 500); | |
} else { | |
window.location.href = "{{ path('_security_logout') }}"; | |
} | |
}); | |
} | |
} | |
</script> | |
<div id="symfony-wrapper"> | |
<div id="symfony-header"> | |
<a href="{{ path('_welcome') }}"> | |
<img src="{{ asset('bundles/acmedemo/images/logo.gif') }}" alt="Symfony"> | |
</a> | |
<form id="symfony-search" method="GET" action="http://symfony.com/search"> | |
<label for="symfony-search-field"><span>Search on Symfony Website</span></label> | |
<input name="q" id="symfony-search-field" type="search" placeholder="Search on Symfony website" class="medium_txt"> | |
<input type="submit" class="symfony-button-grey" value="OK" /> | |
</form> | |
</div> | |
{% if app.session.flash('notice') %} | |
<div class="flash-message"> | |
<em>Notice</em>: {{ app.session.flash('notice') }} | |
</div> | |
{% endif %} | |
{% block content_header %} | |
<ul id="menu"> | |
{% block content_header_more %} | |
<li><a href="{{ path('_demo') }}">Demo Home</a></li> | |
{% endblock %} | |
</ul> | |
<div style="clear: both"></div> | |
{% endblock %} | |
<div class="symfony-content"> | |
{% block content %} | |
{% endblock %} | |
</div> | |
{% if code is defined %} | |
<h2>Code behind this page</h2> | |
<div class="symfony-content">{{ code|raw }}</div> | |
{% endif %} | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\UserBundle\Security\Provider; | |
use FOS\UserBundle\Model\UserManagerInterface; | |
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; | |
use Symfony\Component\Security\Core\User\UserProviderInterface; | |
use Symfony\Component\Security\Core\User\UserInterface; | |
class MyProvider implements UserProviderInterface | |
{ | |
private $userManager; | |
public function __construct(UserManagerInterface $userManager) | |
{ | |
$this->userManager = $userManager; | |
} | |
public function loadUserByUsername($username) | |
{ | |
$user = $this->userManager->findUserByUsernameOrEmail($username); | |
if (!$user) { | |
throw new UsernameNotFoundException(sprintf('No user with name "%s" was found.', $username)); | |
} | |
return $user; | |
} | |
public function refreshUser(UserInterface $user) | |
{ | |
return $this->userManager->refreshUser($user); | |
} | |
public function supportsClass($class) | |
{ | |
return $this->userManager->supportsClass($class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AcmeUserBundle: | |
resource: "@AcmeUserBundle/Resources/config/routing.yml" | |
prefix: / | |
fos_user_security: | |
resource: "@FOSUserBundle/Resources/config/routing/security.xml" | |
fos_user_profile: | |
resource: "@FOSUserBundle/Resources/config/routing/profile.xml" | |
prefix: /profile | |
fos_user_register: | |
resource: "@FOSUserBundle/Resources/config/routing/registration.xml" | |
prefix: /register | |
fos_user_resetting: | |
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml" | |
prefix: /resetting | |
fos_user_change_password: | |
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml" | |
prefix: /profile | |
_security_check: | |
pattern: /login_check | |
_security_logout: | |
pattern: /logout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_welcome: | |
pattern: / | |
defaults: { _controller: AcmeDemoBundle:Welcome:index } | |
_facebook_secured: | |
pattern: /secured/ | |
defaults: { _controller: AcmeDemoBundle:Welcome:index } | |
_demo_secured: | |
resource: "@AcmeDemoBundle/Controller/SecuredController.php" | |
type: annotation | |
_demo: | |
resource: "@AcmeDemoBundle/Controller/DemoController.php" | |
type: annotation | |
prefix: /demo | |
_assetic: | |
resource: . | |
type: assetic | |
_wdt: | |
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml" | |
prefix: /_wdt | |
_profiler: | |
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml" | |
prefix: /_profiler | |
_configurator: | |
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml" | |
prefix: /_configurator | |
_main: | |
resource: routing.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
security: | |
factories: | |
- "%kernel.root_dir%/../vendor/bundles/FOS/FacebookBundle/Resources/config/security_factories.xml" | |
encoders: | |
FOS\UserBundle\Model\UserInterface: sha512 | |
role_hierarchy: | |
ROLE_ADMIN: ROLE_USER | |
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] | |
providers: | |
custom: | |
id: acme_user.my_provider | |
my_fos_facebook_provider: | |
id: my.facebook.user | |
firewalls: | |
dev: | |
pattern: ^/(_(profiler|wdt)|css|images|js)/ | |
security: false | |
login: | |
pattern: ^/demo/secured/login$ | |
security: false | |
secured_area: | |
pattern: ^/demo/secured/ | |
form_login: | |
check_path: /demo/secured/login_check | |
login_path: /demo/secured/login | |
logout: | |
path: /demo/secured/logout | |
target: /demo/ | |
#anonymous: ~ | |
#http_basic: | |
# realm: "Secured Demo Area" | |
main: | |
pattern: ^/ | |
form_login: | |
provider: custom | |
csrf_provider: form.csrf_provider | |
logout: true | |
anonymous: true | |
public: | |
pattern: .* | |
fos_facebook: | |
app_url: "http://apps.facebook.com/speeddator/" | |
server_url: "http://localhost/facebookApp/" | |
login_path: ^/login | |
check_path: ^/login_check$ | |
default_target_path: / | |
provider: my_fos_facebook_provider | |
anonymous: true | |
logout: | |
handlers: ["fos_facebook.logout_handler"] | |
access_control: | |
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } | |
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } | |
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } | |
- { path: ^/admin/, role: ROLE_ADMIN } | |
- { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with fos_facebook | |
- { path: ^/facebook/, role: [ROLE_FACEBOOK] } | |
- { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\UserBundle\Entity; | |
use FOS\UserBundle\Entity\User as BaseUser; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="fos_user") | |
*/ | |
class User extends BaseUser | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\Column(type="integer") | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
protected $id; | |
public function __construct() | |
{ | |
parent::__construct(); | |
// your own logic | |
} | |
/** | |
* @var string | |
*/ | |
protected $firstname; | |
/** | |
* @var string | |
*/ | |
protected $lastname; | |
/** | |
* @var string | |
*/ | |
protected $facebookID; | |
public function serialize() | |
{ | |
return serialize(array($this->facebookId, parent::serialize())); | |
} | |
public function unserialize($data) | |
{ | |
list($this->facebookId, $parentData) = unserialize($data); | |
parent::unserialize($parentData); | |
} | |
/** | |
* @return string | |
*/ | |
public function getFirstname() | |
{ | |
return $this->firstname; | |
} | |
/** | |
* @param string $firstname | |
*/ | |
public function setFirstname($firstname) | |
{ | |
$this->firstname = $firstname; | |
} | |
/** | |
* @return string | |
*/ | |
public function getLastname() | |
{ | |
return $this->lastname; | |
} | |
/** | |
* @param string $lastname | |
*/ | |
public function setLastname($lastname) | |
{ | |
$this->lastname = $lastname; | |
} | |
/** | |
* Get the full name of the user (first + last name) | |
* @return string | |
*/ | |
public function getFullName() | |
{ | |
return $this->getFirstName() . ' ' . $this->getLastname(); | |
} | |
/** | |
* @param string $facebookID | |
* @return void | |
*/ | |
public function setFacebookID($facebookID) | |
{ | |
$this->facebookID = $facebookID; | |
$this->setUsername($facebookID); | |
$this->salt = ''; | |
} | |
/** | |
* @return string | |
*/ | |
public function getFacebookID() | |
{ | |
return $this->facebookID; | |
} | |
/** | |
* @param Array | |
*/ | |
public function setFBData($fbdata) | |
{ | |
if (isset($fbdata['id'])) { | |
$this->setFacebookID($fbdata['id']); | |
$this->addRole('ROLE_FACEBOOK'); | |
} | |
if (isset($fbdata['first_name'])) { | |
$this->setFirstname($fbdata['first_name']); | |
} | |
if (isset($fbdata['last_name'])) { | |
$this->setLastname($fbdata['last_name']); | |
} | |
if (isset($fbdata['email'])) { | |
$this->setEmail($fbdata['email']); | |
} | |
} | |
/** | |
* Get id | |
* | |
* @return integer | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment