PHPackages                             moz-morris/cakephp-facebook-auth - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. moz-morris/cakephp-facebook-auth

ActiveCakephp-plugin[Authentication &amp; Authorization](/categories/authentication)

moz-morris/cakephp-facebook-auth
================================

Facebook authentication handler for CakePHP 2.0

12131PHP

Since Jan 12Pushed 13y ago3 watchersCompare

[ Source](https://github.com/MozMorris/FacebookAuthenticate-CakePhp-Authentication-Handler)[ Packagist](https://packagist.org/packages/moz-morris/cakephp-facebook-auth)[ RSS](/packages/moz-morris-cakephp-facebook-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

FacebookAuthenticate - CakePhp Facebook Authentication Handler
==============================================================

[](#facebookauthenticate---cakephp-facebook-authentication-handler)

- Author: Moz Morris ()
- version 1.1
-
- license: MIT

The purpose of the Facebook Authentication Handler is to provide Facebook Authentication for your CakePHP 2.0 or later based application. The handler has been built following Cake's recommended approach for building [custom authentication objects](http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html?#creating-custom-authentication-objects "Authentication — CakePHP Cookbook v2.0.0 documentation") for use with the built in AuthComponent. The handler itself is part a *FacebookAuth* plugin, though this is essentially to make the handler easily redistributable with example configuration settings and an example controller detailing a typical use case scenario.

It should be noted that though this handler stores the access token returned by Facebook, it **does not** currently provide a means to makes calls to the Graph API. It's function is to provide authentication. Of course, you could use the access token and your preferred method to communicate with Facebook.

Changelog
=========

[](#changelog)

- 1.0 Sharing it with the world for the very first time.
- 1.1 Add email &amp; name fields by default &amp; ensure handler uses configuration settings

Installation
============

[](#installation)

Get the code
------------

[](#get-the-code)

### Via Git

[](#via-git)

First clone the repository into a new `app/Plugin/FacebookAuth` directory

```
git clone git://github.com/MozMorris/FacebookAuthenticate-CakePhp-Authentication-Handler.git /path/to/your/app/Plugin/FacebookAuth

```

### Via Composer

[](#via-composer)

Add a dependency to your `composer.json` file. (Looks like the CakePHP convention is to have the `composer.json` file located under `app/`)

```
"require": {
  "moz-morris/cakephp-facebook-auth": "dev-master"
}

```

Then `composer install` or `composer update`. You might need to add `"minimum-stability": "dev"` to you `composer.json` file.

Facebook Application &amp; App Configuration
--------------------------------------------

[](#facebook-application--app-configuration)

1. Rename the example configuration *FacebookConfig.ini.example* to **FacebookConfig.ini**. It can be found under app/Plugin/FacebookAuth/Config/
2. Head on over to the [Facebook Developer App](https://developers.facebook.com/apps) and either setup a new application to get a App ID/API Key &amp; App Secret, or note down the ones from your existing app. **NOTE: Your 'App Domain' must be the same host as you're accessing your site with to enable Auth.** Otherwise, when you attempt to authenticate, Facebook will return "API Error Code: 191 | API Error Description: The specified URL is not owned by the application | Error Message: Invalid redirect\_uri: Given URL is not allowed by the Application configuration."
3. Update your FacebookConfig.ini with the App ID/API Key &amp; App Secret.
4. Load the plugin and it's configuration in your bootstrap file *app/Config/bootstrap.php*
5. Configure the FacebookAuth handler at runtime

Loading the plugin and configuration (*bootstrap.php*):

```
/**
 * Load custom configuration files using the IniReader class
 */
App::uses('IniReader', 'Configure');
Configure::config('default', new IniReader(APP . 'Plugin' . DS . 'FacebookAuth' . DS . 'Config' . DS));
Configure::load('FacebookConfig', 'default');

/**
 * Load Facebook Plugin
 */
CakePlugin::load('FacebookAuth');

```

Configuring the handler at runtime:

```
public function beforeFilter()
{
  parent::beforeFilter();

  /**
   * Configure FacebookAuth handler
   */
  $this->Auth->authenticate['FacebookAuth.Facebook']['application'] = array(
   'id'     => Configure::read('facebook.app_id'),
   'secret' => Configure::read('facebook.app_secret')
  );
}

```

Database
--------

[](#database)

Add `email`, `name`, `facebook_user_id`, `facebook_access_token` fields to your User model. In this example we're adding the fields to the *users* table which is pretty much the standard for Cake apps using some kind of user authentication. If your app is slightly different, then make the relevant changes.

```
ALTER TABLE `users` ADD `email` VARCHAR(255)  NOT NULL  DEFAULT '';
ALTER TABLE `users` ADD `name` VARCHAR(255)  NOT NULL  DEFAULT '';
ALTER TABLE `users` ADD `facebook_user_id` BIGINT  NULL  DEFAULT NULL;
ALTER TABLE `users` ADD `facebook_access_token` VARCHAR(255)  NULL  DEFAULT NULL;

```

Usage
=====

[](#usage)

Basic example:

```
public $components = array(
  'Auth'=> array(
    'authenticate' => array(
      'FacebookAuth.Facebook'
    )
  )
);

```

Slightly more interesting:

```
public $components = array(
  'Auth'=> array(
    'loginAction' => array(
      'controller' => 'users',
      'action' => 'login'
    ),
    'loginRedirect' => array(
      'controller' => 'users',
      'action' => 'my_account'
    ),
    'authError' => 'Did you really think you are allowed to see that?',
    'authenticate' => array(
      'FacebookAuth.Facebook' => array(
        'fields' => array(
          'username' => 'email',
    			'password' => 'password'
        )
      )
    )
  )
);

```

See the Cake Book for more ways to configure your [CakePHP AuthComponent](http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html "Authentication — CakePHP Cookbook v2.0.0 documentation").

There is also an example controller included within the plugin that shows how you could implement the handler.

```
app/Plugin/FacebookAuth/Controller/ExampleController.php

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9de031362ec823dc8e1e2c32122ec4ca6dee58e3c691af40ed76ec5292805427?d=identicon)[MozMorris](/maintainers/MozMorris)

---

Top Contributors

[![mozmorris](https://avatars.githubusercontent.com/u/156303?v=4)](https://github.com/mozmorris "mozmorris (12 commits)")

### Embed Badge

![Health badge](/badges/moz-morris-cakephp-facebook-auth/health.svg)

```
[![Health](https://phpackages.com/badges/moz-morris-cakephp-facebook-auth/health.svg)](https://phpackages.com/packages/moz-morris-cakephp-facebook-auth)
```

###  Alternatives

[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)[beatswitch/lock

A flexible, driver based Acl package for PHP 5.4+

870304.7k2](/packages/beatswitch-lock)[amocrm/amocrm-api-library

amoCRM API Client

182728.5k6](/packages/amocrm-amocrm-api-library)[vonage/jwt

A standalone package for creating JWTs for Vonage APIs

424.1M4](/packages/vonage-jwt)

PHPackages © 2026

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