PHPackages                             admad/cakephp-hybridauth - 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. admad/cakephp-hybridauth

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

admad/cakephp-hybridauth
========================

A CakePHP plugin for using the HybridAuth social sign on library

4.2.0(7y ago)7859.6k↓100%39[5 issues](https://github.com/ADmad/CakePHP-HybridAuth/issues)MITPHP

Since Apr 10Pushed 4y ago16 watchersCompare

[ Source](https://github.com/ADmad/CakePHP-HybridAuth)[ Packagist](https://packagist.org/packages/admad/cakephp-hybridauth)[ Docs](http://github.com/ADmad/CakePHP-HybridAuth)[ RSS](/packages/admad-cakephp-hybridauth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (17)Used By (0)

If you are using CakePHP 3.4+ checkout my [ADmad/cakephp-social-auth](https://github.com/ADmad/cakephp-social-auth) instead.
----------------------------------------------------------------------------------------------------------------------------

[](#if-you-are-using-cakephp-34-checkout-my-admadcakephp-social-auth-instead)

CakePHP HybridAuth Plugin
=========================

[](#cakephp-hybridauth-plugin)

[![Total Downloads](https://camo.githubusercontent.com/b6445017ba6aec5e8782084ca6b06ff597b333656d2943a92c6f798bda4a7b9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f41446d61642f43616b655048502d487962726964417574682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/admad/cakephp-hybridauth)[![License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A CakePHP plugin which allows using the [HybridAuth](http://hybridauth.github.io/hybridauth/)social sign on library.

Requirements
------------

[](#requirements)

- CakePHP 3.1+.

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

[](#installation)

Run:

```
composer require --prefer-dist admad/cakephp-hybridauth

```

Setup
-----

[](#setup)

Load the plugin by running following command in terminal:

```
bin/cake plugin load ADmad/HybridAuth -b -r

```

or by manually adding following line to your app's `config/bootstrap.php`:

```
Plugin::load('ADmad/HybridAuth', ['bootstrap' => true, 'routes' => true]);
```

Configuration
-------------

[](#configuration)

Make a config file `config/hybridauth.php`:

```
use Cake\Core\Configure;

return [
    'HybridAuth' => [
        'providers' => [
            'Google' => [
                'enabled' => true,
                'keys' => [
                    'id' => '',
                    'secret' => ''
                ]
            ],
            'Facebook' => [
                'enabled' => true,
                'keys' => [
                    'id' => '',
                    'secret' => ''
                ],
                'scope' => 'email, user_about_me, user_birthday, user_hometown'
            ],
            'Twitter' => [
                'enabled' => true,
                'keys' => [
                    'key' => '',
                    'secret' => ''
                ],
                'includeEmail' => true // Only if your app is whitelisted by Twitter Support
            ]
        ],
        'debug_mode' => Configure::read('debug'),
        'debug_file' => LOGS . 'hybridauth.log',
    ]
];
```

For more information about the hybridauth configuration array check

Database
--------

[](#database)

The plugin expects that you have a users table with at least `email` field and a `social_profiles` table. You can run

```
bin/cake migrations migrate -p ADmad/HybridAuth

```

to generate the `social_profiles` tabel using a migration file provided with the plugin.

Usage
-----

[](#usage)

Check the CakePHP manual on how to configure and use the `AuthComponent` with required authentication handler. You would have something like this in your `AppController`'s `initialize()` method.

```
$this->loadComponent('Auth', [
    'authenticate' => [
        'Form',
        'ADmad/HybridAuth.HybridAuth' => [
            // All keys shown below are defaults
            'fields' => [
                'provider' => 'provider',
                'openid_identifier' => 'openid_identifier',
                'email' => 'email'
            ],

            'profileModel' => 'ADmad/HybridAuth.SocialProfiles',
            'profileModelFkField' => 'user_id',

            'userModel' => 'Users',

            // The URL Hybridauth lib should redirect to after authentication.
            // If no value is specified you are redirect to this plugin's
            // HybridAuthController::authenticated() which handles persisting
            // user info to AuthComponent and redirection.
            'hauth_return_to' => null
        ]
    ]
]);
```

**Note:** When specifying `loginRedirect` and `loginAction` URLs for AuthComponent be sure to add `'plugin' => false` (or appropiate plugin name) to the URL array.

Your controller's login action should be similar to this:

```
public function login() {
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error(__('Invalid username or password, try again'));
    }
}
```

**Note:** When your action calls `$this->Auth->identify()` the method may not return. The authenticator may need to redirect to the provider's site to complete the identification procedure. It's important not to implement any important business logic that depends upon the `identify()` method returning.

On your login page you can create links to initiate authentication using required providers. Specify the provider name using variable named `provider` in query string.

```
echo $this->Form->postLink(
    'Login with Google',
    ['controller' => 'Users', 'action' => 'login', '?' => ['provider' => 'Google']]
);
```

We use a POST link here instead of a normal link to prevent search bots and other crawlers from following the link. (Adding "nofollow" attribute to link doesn't suffice as it's often ignored by bots/crawlers.)

Once a user is authenticated through the provider the authenticator gets the user profile from the identity provider and using that tries to find the corresponding user record in your app's users table. If no user is found emits a `HybridAuth.newUser`event. You must setup a listener for this event which save new user record to your users table and return an entity for the new user. Here's how you can setup a method of your `UsersTable` as callback for the event.

If you also want to monitor all logins - and execute e.g. a login counter - you can listen for the `HybridAuth.login` event.

```
public function initialize(array $config)
{
    $this->hasMany('ADmad/HybridAuth.SocialProfiles');

    \Cake\Event\EventManager::instance()->on('HybridAuth.newUser', [$this, 'createUser']);
    \Cake\Event\EventManager::instance()->on('HybridAuth.login', [$this, 'updateUser']);
}

public function createUser(\Cake\Event\Event $event)
{
    // Entity representing record in social_profiles table
    $profile = $event->data()['profile'];

    // Make sure here that all the required fields are actually present

    $user = $this->newEntity(['email' => $profile->email]);
    $user = $this->save($user);

    if (!$user) {
        throw new \RuntimeException('Unable to save new user');
    }

    return $user;
}

public function updateUser(\Cake\Event\Event $event, array $user)
{
    $this->updateAll(['logins = logins + 1', 'last_login' => new FrozenTime()], ['id' => $user['id']]);
}
```

Additionally, you can also get a flash message for login back using the `HybridAuth.login` event:

```
// In your AppController
    public function initialize()
    {
        EventManager::instance()->on('HybridAuth.login', [$this->MyComponent, 'updateUser']);
    }

// In your MyComponent
    public $components = [
        'Flash'
    ];

    public function updateUser(Event $event, array $user)
    {
        $this->Flash->success(__('You are now logged in'));
    }
```

Twitter &amp; email addresses
-----------------------------

[](#twitter--email-addresses)

If you are trying to achieve a 'Sign in using Twitter' functionality, and you require the users *email address*, you need to specifically get your application [white-listed by Twitter Support using this form](https://support.twitter.com/forms/platform) and selecting 'I need access to special permissions'. Then you can use the `'includeEmail' => true` configuration option.

Copyright
---------

[](#copyright)

Copyright 2016 ADmad

License
-------

[](#license)

[See LICENSE](LICENSE.txt)

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 84.9% 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 ~85 days

Recently: every ~147 days

Total

15

Last Release

2859d ago

Major Versions

1.0.0 → 3.0.02015-04-10

3.0.2 → 4.0.02016-02-24

1.0.1 → 4.0.52016-11-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/e31753bdd616948c7c8978ea9b5805378f75bfa62564e69c0aa2fd67aaf418c5?d=identicon)[ADmad](/maintainers/ADmad)

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (135 commits)")[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (7 commits)")[![davidyell](https://avatars.githubusercontent.com/u/49889?v=4)](https://github.com/davidyell "davidyell (6 commits)")[![chrisvogt](https://avatars.githubusercontent.com/u/1934719?v=4)](https://github.com/chrisvogt "chrisvogt (5 commits)")[![damianoporta](https://avatars.githubusercontent.com/u/7131996?v=4)](https://github.com/damianoporta "damianoporta (2 commits)")[![sakulstra](https://avatars.githubusercontent.com/u/4396533?v=4)](https://github.com/sakulstra "sakulstra (1 commits)")[![kaffineaddict](https://avatars.githubusercontent.com/u/1271668?v=4)](https://github.com/kaffineaddict "kaffineaddict (1 commits)")[![lfk](https://avatars.githubusercontent.com/u/1514950?v=4)](https://github.com/lfk "lfk (1 commits)")[![OtterlyOlive](https://avatars.githubusercontent.com/u/517111?v=4)](https://github.com/OtterlyOlive "OtterlyOlive (1 commits)")

---

Tags

cakephpcakephp-pluginhybridauthphpsocial-logincakephpsocialhybridauthmulti-providersocial authenticationsocial signon

### Embed Badge

![Health badge](/badges/admad-cakephp-hybridauth/health.svg)

```
[![Health](https://phpackages.com/badges/admad-cakephp-hybridauth/health.svg)](https://phpackages.com/packages/admad-cakephp-hybridauth)
```

###  Alternatives

[cakedc/users

Users Plugin for CakePHP

524897.0k16](/packages/cakedc-users)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

129228.6k10](/packages/dereuromark-cakephp-tinyauth)[admad/cakephp-jwt-auth

CakePHP plugin for authenticating using JSON Web Tokens

160680.3k8](/packages/admad-cakephp-jwt-auth)[markstory/acl_extras

Additional tools for managing DB ACL in CakePHP applications.

155311.0k](/packages/markstory-acl-extras)[cakedc/auth

Auth objects for CakePHP

31630.0k2](/packages/cakedc-auth)[uafrica/oauth-server

OAuth Server for CakePHP 3 using the PHP League's OAuth2 Server

5172.1k](/packages/uafrica-oauth-server)

PHPackages © 2026

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