lzakrzewski / facebook-authentication-bundle
This bundle helps you to add "Login with facebook" feature to your app
Installs: 73
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.4
- friendsofsymfony/user-bundle: ~2.0@dev
- lzakrzewski/facebook-authentication-adapter: ~1.0
Requires (Dev)
- doctrine/doctrine-bundle: ~1.3
- doctrine/orm: ~2.3
- monolog/monolog: ~1.0
- phpunit/phpunit: ~4.8
- symfony/browser-kit: ~2.7
- symfony/symfony: ~2.7
This package is not auto-updated.
Last update: 2024-11-01 19:20:13 UTC
README
This bundle provides Facebook authentication for your Symfony2 app using the FOSUserBundle. Target: Keep it minimalistic and use existing components from Symfony2 and FOSUserBundle.
Features
- Enable login with facebook feature to your app,
- Add user created from facebook data to your app.
Requirements
"require": { "php": ">=5.4", "friendsofsymfony/user-bundle": "~2.0@dev", "lzakrzewski/facebook-authentication-adapter": "~1.0" }
Supported Facebook API version
- v2.5
Installation
Step 1: Integrate FOSUserBundle with your app
Read the Documentation for master.
Step 2: Require the FacebookAuthenticationBundle with composer
composer require lzakrzewski/facebook-authentication-bundle "~1.0"
Step 3: Enable the FacebookAuthenticationBundle
// app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Lzakrzewski\FacebookAuthenticationBundle\LzakrzewskiFacebookAuthenticationBundle(), // ... ); }
Step 4: Implement your User class with FacebookUser
<?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.
Step 5: Configure the config.yml
Minimal configuration:
lzakrzewski_facebook_authentication: app_id: 1234 app_secret: secret
Parameters: app_id
and secret
are needed to get access token: Access Tokens.
Example of full configuration:
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.
Step 6: Confgure your routing.yml
facebook_login_path: pattern: /facebook/login
Step 7: Enable facebook_listener
in your security.yml
# 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 # ...
Step 8: Update your database schema
php app/console doctrine:schema:update --force
Step 9: Setup your facebook app
Now when route /facebook/login
will be requested then procedure of code exchange will be process Code exchange.