title: Cakephp ADmad CakePHP-HybridAuth Plugin threw Exception
body: <p>I am using ADmad/CakePHP-HybridAuth Plugin for Social auth. For this i followed the doc that given at <a href="https://github.com/ADmad/CakePHP-HybridAuth" rel="nofollow noreferrer">https://github.com/ADmad/CakePHP-HybridAuth</a>. I did same as it that done on doc but i am facing an Exception :-</p>
  
  <p><strong>You must attach a listener for "HybridAuth.newUser" event which saves new user record and returns an user entity.</strong></p>
  
  <p>Kindly help me to solve this problem.</p>
  
  <p><strong>Example:</strong></p>
  
  <p>UserModel:</p>
  
  <pre><code>    &lt;?php
  namespace Accounts\Model\Table;
  
  use Accounts\Model\Entity\User;
  use Cake\ORM\Query;
  use Cake\ORM\RulesChecker;
  use Cake\ORM\Table;
  use Cake\Validation\Validation;
  use Cake\Validation\Validator;
  use Cake\Event\Event;
  use Cake\Event\EventManager;
  /**
   * Users Model
   *
   * @property \Cake\ORM\Association\BelongsTo $Roles
   */
  class UsersTable extends Table
  {
  
  
      public function initialize(array $config)
      {
          parent::initialize($config);
  
          $this-&gt;table('users');
          $this-&gt;displayField('first_name');
          $this-&gt;primaryKey('id');
  
          $this-&gt;addBehavior('Timestamp');
  
          $this-&gt;belongsTo('Roles', [
              'foreignKey' =&gt; 'role_id',
              'joinType' =&gt; 'LEFT',
              'className' =&gt; 'Accounts.Roles',
          ]);
  
          $this-&gt;hasOne('Profiles', [
              'foreignKey' =&gt; 'user_id',
              'className' =&gt; 'Accounts.Profiles',
              'dependent' =&gt; true
          ]);
  
          $this-&gt;hasMany('ADmad/HybridAuth.SocialProfiles');
          EventManager::instance()-&gt;on('HybridAuth.newUser', [$this, 'createUser']);
      }
  
      public function createUser(Event $event) {
          // Entity representing record in social_profiles table
          $profile = $event-&gt;data()['profile'];
  
          $user = $this-&gt;newEntity(['email' =&gt; $profile-&gt;email]);
          $user = $this-&gt;save($user);
  
          if (!$user) {
              throw new \RuntimeException('Unable to save new user');
          }
  
          return $user;
      }
  
  
      public function validationDefault(Validator $validator)
      {
          $validator
              -&gt;integer('id')
              -&gt;allowEmpty('id', 'create');
  
          return $validator;
      }
  
  
      public function buildRules(RulesChecker $rules)
      {
          $rules-&gt;add($rules-&gt;isUnique(['email']));
          $rules-&gt;add($rules-&gt;isUnique(['username']));
          $rules-&gt;add($rules-&gt;existsIn(['role_id'], 'Roles'));
          return $rules;
      }
  
      public function beforeSave($event, $entity, $options){
          if($entity-&gt;first_name)
              $entity-&gt;slug = $this-&gt;createSlug($entity-&gt;first_name);
      }
  }
  </code></pre>
  
  <p><strong>In App Controller :</strong></p>
  
  <pre><code>$this-&gt;loadComponent('Auth', [
              'authenticate' =&gt; [
                  'Form' =&gt; [
                      'fields' =&gt; [
                          'username' =&gt; 'username',
                          'password' =&gt; 'password'
                      ]
                  ],
                  'ADmad/HybridAuth.HybridAuth'
              ],
              'loginAction' =&gt; [
                  'controller' =&gt; 'Users',
                  'action' =&gt; 'login',
                  'plugin' =&gt; 'Accounts'
              ],
              'loginRedirect' =&gt; [
                  'controller' =&gt; 'Users',
                  'action' =&gt; 'login',
                  'plugin' =&gt; 'Accounts'
              ],
  
          ]);
  </code></pre>
  
  <p>In UsersController:</p>
  
  <pre><code>public function login()
      {
          if( $this-&gt;Auth-&gt;user()){
              $this-&gt;redirect(array('action'=&gt;'index', 'controller'=&gt;'Users', 'plugin'=&gt;'Accounts'));
          }else{
  
              if ($this-&gt;request-&gt;is('post') || $this-&gt;request-&gt;query('provider')) {
  
                  $user = $this-&gt;Auth-&gt;identify();
                  if ($user) {
                      $this-&gt;Auth-&gt;setUser($user);
                      return $this-&gt;redirect($this-&gt;Auth-&gt;redirectUrl());
                  }
                  $this-&gt;Flash-&gt;error(__('Invalid username or password, try again'));
              }
          }
      }
  </code></pre>
  
  <p><strong>Error Page</strong>
  <a href="https://i.stack.imgur.com/VemEj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VemEj.png" alt="enter image description here"></a></p>