2016-06-24 27 views
1

私はソーシャルログインを追加する必要があるCakePHP 3プロジェクトに取り組んでいます。私はHereCakePHP 3:Hybriauthの設定が指定されたパスに存在しません

からチュートリアル以下HybridAuthを使用していることについては

今私はhttp://website.com/users/social/Facebookにアクセスすると、私は

Hybriauth config does not exist on the given path. 

としてエラーを取得する私のUsersControllerは、私がインストールされている

<?php 
namespace App\Controller; 

use App\Controller\AppController; 
use Cake\Event\Event; 

/** 
* Users Controller 
* 
* @property \App\Model\Table\UsersTable $Users 
*/ 
class UsersController extends AppController 
{ 

    public function beforeFilter(Event $event) 
    { 
    parent::beforeFilter($event); 
    $this->Auth->allow(['register','logout','social','social_redirect']); 
    } 

    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')); 
     } 
    } 

    public function social($provider) 
    { 
     /* Include the config file */ 
     require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'config.php'); 
     require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'Hybrid' . DS . 'Auth.php'); 

     /* Initiate Hybrid_Auth Function */ 
     $hybridauth = new \Hybrid_Auth($config); 
     $authProvider = $hybridauth->authenticate($provider); 
     $user_profile = $authProvider->getUserProfile(); 

     /* Modify here as per need. This is for demo */ 
     if ($user_profile && isset($user_profile->identifier)) { 
     echo "<b>Name</b> : " . $user_profile->displayName . "<br />"; 
     echo "<b>Profile URL : </b>" . $user_profile->profileURL . "<br />"; 
     echo "<b>Image : </b>" . $user_profile->photoURL . "<br />"; 
     echo "<img src='" . $user_profile->photoURL . "'<br />"; 
     echo "<b>Email : </b>" . $user_profile->email . "<br />"; 
     echo "<br /> <a href='logout.php'>Logout</a>"; 
     } 
     exit; 

     /* Example demo for FB authorize Action */ 
     #Facebook authorize 
     if ($this->request->params['pass'][0] == 'Facebook') { 
     if ($user_profile && isset($user_profile->identifier)) { 
      $this->authorize_facebook($user_profile); 
     } 
     } 
    } 

    public function social_redirect() 
    { 
     $this->layout = false; 
     $this->autoRender = false; 
     require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'config.php'); 
     require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'Hybrid' . DS . 'Auth.php'); 
     require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'Hybrid' . DS . 'Endpoint.php'); 

     $hybridauth = new \Hybrid_Auth($config); 
     \Hybrid_Endpoint::process(); 
    } 

    public function authorize_facebook($user_profile) 
    { 
     $provider = 'Facebook'; 
     $provider_uid = $user_profile->identifier; 

     $userExist = $this->Users->find('all')->where(['Users.provider' => $provider, 'Users.provider_uid' => $user_profile->identifier])->first(); 

     if ((isset($userExist)) && ($userExist)) { 
     $session = $this->request->session(); 
     $session->delete('auth_sess_var'); 
     $session->destroy(); 
     $this->Auth->setUser($userExist->toArray()); 
     $session->write('auth_sess_var', $userExist); 
     return $this->redirect($this->Auth->redirectUrl()); 
     } else { 

     /* Create new user entity */ 
     $user = $this->Users->newEntity(); 
     $tmp_hash = md5(rand(0, 1000)); 
     $tmp_id = time(); 

     /* Save individual data */ 
     $user->tmp_id = $tmp_id; 
     $firstName = (!empty($user_profile->firstName)) ? $user_profile->firstName : ""; 
     $lastName = (!empty($user_profile->lastName)) ? $user_profile->lastName : ""; 
     $user->name = $firstName . ' ' . $lastName; 
     // $user->username = (!empty($user_profile->firstName) && !empty($user_profile->lastName)) ? strlolower($user_profile->firstName) . "." . strtolower($user_profile->lastName) : ""; 
     // $user->avatar = (!empty($user_profile->photoURL)) ? $user_profile->photoURL : ""; 
     // $user->role = "public"; 
     $user->provider = $provider; 
     $user->provider_uid = $user_profile->identifier; 
     $user->email = !empty($user_profile->email) ? $user_profile->email : ""; 
     $user->password = $user_profile->identifier; 
     // $user->confirm_password = $user_profile->identifier; 
     $user->tmp_hash = $tmp_hash; 
     $user->verified = (!empty($user_profile->emailVerified)) ? 1 : 0; 

     $user = $this->Users->patchEntity($user, $this->request->data); 
     $this->Users->save($user); 

     $userDetails = $this->Users->find('all') 
      ->where(['Users.provider' => $provider, 'Users.provider_uid' => $user_profile->identifier])->first(); 

     /* Destroy previous session before setting new Session */ 
     $session = $this->request->session(); 
     $session->delete('auth_sess_var'); 
     $session->destroy(); 

     /* Set user */ 
     $this->Auth->setUser($userDetails->toArray()); 
     $session->write('auth_sess_var', $userDetails); 
     return $this->redirect($this->Auth->redirectUrl()); 
     } 
    } 

    public function logout() 
    { 
     return $this->redirect($this->Auth->logout()); 
    } 
} 

あるHybridAuth : version 2.5.1composerを使用し、その場所は

です config.php

<?php 

/** 
* HybridAuth 
* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth 
* (c) 2009-2015, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html 
*/ 
// ---------------------------------------------------------------------------------------- 
// HybridAuth Config file: http://hybridauth.sourceforge.net/userguide/Configuration.html 
// ---------------------------------------------------------------------------------------- 

return 
     array(
      "base_url" => "http://website.com/users/social-redirect/", 
      "providers" => array(
       // openid providers 
       "OpenID" => array(
        "enabled" => true 
       ), 
       "Yahoo" => array(
        "enabled" => true, 
        "keys" => array("key" => "", "secret" => ""), 
       ), 
       "AOL" => array(
        "enabled" => true 
       ), 
       "Google" => array(
        "enabled" => true, 
        "keys" => array("id" => "", "secret" => ""), 
       ), 
       "Facebook" => array(
        "enabled" => true, 
        "keys" => array("id" => "id", "secret" => "key"), 
        "trustForwarded" => false 
       ), 
       "Twitter" => array(
        "enabled" => true, 
        "keys" => array("key" => "", "secret" => ""), 
        "includeEmail" => false 
       ), 
       // windows live 
       "Live" => array(
        "enabled" => true, 
        "keys" => array("id" => "", "secret" => "") 
       ), 
       "LinkedIn" => array(
        "enabled" => true, 
        "keys" => array("key" => "", "secret" => "") 
       ), 
       "Foursquare" => array(
        "enabled" => true, 
        "keys" => array("id" => "", "secret" => "") 
       ), 
      ), 
      // If you want to enable logging, set 'debug_mode' to true. 
      // You can also set it to 
      // - "error" To log only error messages. Useful in production 
      // - "info" To log info and error messages (ignore debug messages) 
      "debug_mode" => false, 
      // Path to file writable by the web server. Required if 'debug_mode' is not false 
      "debug_file" => "", 
); 

|/root 
    |- vendor 
     |- hybridauth 
     |- hybridauth 
      |- hybridauth 
      |- Hybrid (directory) 
       |- Auth.php 
       |- ... 
      |- config.php 
      |- index.php 

内容は、コードが間違っていますか?

+0

私のプラグインhttps://github.com/ADmad/CakePHP-HybridAuthを使いやすく、readmeに従ってください。 – ADmad

+0

今日はお試しいただきありがとうございます –

答えて

0

このエラーを取り除く方法です:あなたは(必要)を呼び出し、ユーザーのコントローラで をあなたは変数$の設定に必要とどのようなことを格納する必要があるのconfig.php

require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'config.php'); 

$config = require_once(ROOT . DS . 'vendor' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'hybridauth' . DS . 'config.php'); 

よろしくお願いします。

関連する問題