This bundle provides Facebook authentication for your Symfony2 app using the FOSUserBundle. Target: Keep it minimalistic and use existing components from Symfony2 and FOSUserBundle.
- Enable login with facebook feature to your app,
- Add user created from facebook data to your app.
"require": {
"php": ">=5.4",
"friendsofsymfony/user-bundle": "~2.0@dev",
"lzakrzewski/facebook-authentication-adapter": "~1.0"
}
- v2.5
Read the Documentation for master.
composer require lzakrzewski/facebook-authentication-bundle "~1.0"
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Lzakrzewski\FacebookAuthenticationBundle\LzakrzewskiFacebookAuthenticationBundle(),
// ...
);
}
<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Lzakrzewski\FacebookAuthenticationBundle\Model\FacebookUser;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User extends BaseUser implements FacebookUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="bigint", nullable=true)
*/
private $facebookId;
/** {@inheritdoc} */
public function getFacebookId()
{
return $this->facebookId;
}
/** {@inheritdoc} */
public function setFacebookId($facebookId)
{
$this->facebookId = $facebookId;
}
}
Notice field for store FacebookId should be named facebookId
or Annotation FacebookId
should be used: FacebookId Annotation.
lzakrzewski_facebook_authentication:
app_id: 1234
app_secret: secret
Parameters: app_id
and secret
are needed to get access token: Access Tokens.
lzakrzewski_facebook_authentication:
app_id: 1234
app_secret: secret
scope: ["public_profile", "email", "user_birthday"]
fields: ["name", "email", "birthday"]
Parameters:
scope
An array of permissions: Permissions with Facebook Login,fields
By default, not all the fields in a node or edge are returned when you make a query. You can choose the fields (or edges) you want returned with the "fields" query parameter. Choosing Fields.
Notice
scope
Should containpublic_profile
,email
or more,fields
Should containname
,email
or more.
facebook_login_path:
pattern: /facebook/login
# app/config/security.yml
security:
# ...
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
logout: true
anonymous: true
# Enable facebook_listener
lzakrzewski_facebook: true
# ...
php app/console doctrine:schema:update --force
Now when route /facebook/login
will be requested then procedure of code exchange will be process Code exchange.