PHPackages                             grom/facebook-service-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. grom/facebook-service-provider

AbandonedArchivedLibrary[API Development](/categories/api)

grom/facebook-service-provider
==============================

Facebook API and connect integration into your Silex applications

v1.1.0(12y ago)241.4k6[1 issues](https://github.com/GromNaN/FacebookServiceProvider/issues)MITPHP

Since Mar 2Pushed 10y ago1 watchersCompare

[ Source](https://github.com/GromNaN/FacebookServiceProvider)[ Packagist](https://packagist.org/packages/grom/facebook-service-provider)[ RSS](/packages/grom-facebook-service-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

FacebookServiceProvider
=======================

[](#facebookserviceprovider)

The FacebookServiceProvider adds Facebook Connect and API to your applications.

It integrates [FOSFacebookBundle](https://github.com/FriendsOfSymfony/FOSFacebookBundle) into Silex.

Parameters
----------

[](#parameters)

- **facebook.config:** Configuration of your Facebook application. (appId, secret, fileUpload, )
- **facebook.permissions:** List of permissions required to connect.
- **facebook.session\_prefix:** Prefix for Facebook data.

Services
--------

[](#services)

- **facebook:** Facebook SDK. [Read online documentation](https://developers.facebook.com/docs/reference/php/)

Installation
------------

[](#installation)

Using composer :

```
composer require grom/facebook-service-provider

```

Registering
-----------

[](#registering)

First, you must register the [SecurityServiceProvider](http://silex.sensiolabs.org/doc/providers/security.html#registering).

```
use Silex\Provider\FacebookServiceProvider;

$app->register(new FacebookServiceProvider(), array(
    'facebook.config' => array(
        'appId'      => 'YOUR_APP_ID',
        'secret'     => 'YOUR_APP_SECRET',
        'fileUpload' => false, // optional
    ),
    'facebook.permissions' => array('email'),
));
```

Authentication
--------------

[](#authentication)

To authenticate users with Facebook Connect, first you need to register the [SecurityServiceProvider](http://silex.sensiolabs.org/doc/providers/security.html).

To enable Facebook authentication, just add a "facebook" option to your firewall configuration.

```
$app['security.firewalls'] = array(
    'private' => array(
        'pattern' => '^/',
        'facebook' => array(
            'check_path' => '/login_check',
            'login_path' => '/login',
        ),
        // Users are identified by their Facebook UID
        'users' => array(
            // This is Mark Zuckerberg
            '4' => array('ROLE_USER', null),
        ),
    ),
);
```

If you don't set a `login_path`, the user is redirected to Facebook.

Developers of embedded Facebook Applications may define `app_url`, `server_url` and `display` options.

Defining a custom User Provider and automatic user creation##
-------------------------------------------------------------

[](#defining-a-custom-user-provider-and-automatic-user-creation)

The UserProvider used to find Facebook user is similar to the [username/password UserProvider](http://silex.sensiolabs.org/doc/providers/security.html#defining-a-custom-user-provider). The differences are that users are identified by their Facebook UID instead of their username.

If the Facebook UID is not found in your database, the user provider can create the user automatically. You simply have to implements the method `FOS\FacebookBundle\Security\User\UserProviderInterface::createUserFromUid`

```
use FOS\FacebookBundle\Security\User\UserManagerInterface as FacebookUserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Doctrine\DBAL\Connection;

class FacebookUserProvider implements FacebookUserProviderInterface
{
    private $conn;

    public function __construct(Connection $conn)
    {
        $this->conn = $conn;
    }

    public function loadUserByUsername($uid)
    {
        $stmt = $this->conn->executeQuery('SELECT * FROM users WHERE username = ?', array($uid));

        if (!$user = $stmt->fetch()) {
            throw new UsernameNotFoundException(sprintf('Facebook UID "%s" does not exist.', $uid));
        }

        return new User($user['username'], null, explode(',', $user['roles']), true, true, true, true);
    }

    public function refreshUser(UserInterface $user)
    {
        if (!$user instanceof User) {
            throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
        }

        return $this->loadUserByUsername($user->getUsername());
    }

    public function createUserFromUid($uid)
    {
        $this->conn->insert('users', array(
            'username' => $uid,
            'roles'    => 'ROLE_USER',
        ));

        return $this->loadUserByUsername($uid);
    }

    public function supportsClass($class)
    {
        return $class === 'Symfony\Component\Security\Core\User\User';
    }
}
```

Now use your custom user provider.

```
$app['security.firewalls'] = array(
    'default' => array(
        'facebook' => array(
        ),
        'users' => $app->share(function () use ($app) {
            return new FacebookUserProvider($app['db']);
        }),
    ),
);
```

Facebook Graph API
------------------

[](#facebook-graph-api)

Once a user is authenticated with Facebook, you can make Facebook Graph API requests.

```
$app->get('/', function () use ($app) {
    $user = $app['facebook']->api('/me');

    return 'Welcome ' . $user['name'];
});
```

Look at the [Facebook Graph Explorer](https://developers.facebook.com/tools/explorer/).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~186 days

Total

3

Last Release

4454d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/400034?v=4)[Jérôme Tamarelle](/maintainers/GromNaN)[@GromNaN](https://github.com/GromNaN)

---

Top Contributors

[![GromNaN](https://avatars.githubusercontent.com/u/400034?v=4)](https://github.com/GromNaN "GromNaN (15 commits)")

### Embed Badge

![Health badge](/badges/grom-facebook-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/grom-facebook-service-provider/health.svg)](https://phpackages.com/packages/grom-facebook-service-provider)
```

###  Alternatives

[tobiassjosten/facebook-service-provider

Silex ServiceProvider for the Facebook SDK

266.1k](/packages/tobiassjosten-facebook-service-provider)[glen/slack-unfurl

Extensible Slack App for link unfurling

211.4k5](/packages/glen-slack-unfurl)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
