php - Oauth 认证 facebook - cakePHP 插件

标签 php facebook cakephp oauth facebook-login

我对此很困惑plugin .

只需复制粘贴演示,但当我尝试连接 facebook 时出现此错误:

The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

完整代码:

<?php

class ExamplesController extends AppController {

  public $components = array(
    'Auth'=> array(
      'loginAction' => array(
        'controller' => 'examples',
        'action'     => 'login'
      ),
      'loginRedirect' => array(
        'controller' => 'examples',
        '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'
          )
        )
      )
    )
  );

    public function index() {
    }

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

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

    $this->Auth->allowedActions = array_merge($this->Auth->allowedActions, array('login'));
  }

  public function login()
  {
    if (!$this->Auth->login()) {
      /**
       * Get config for Facebook redirect
       */
      $clientId    = Configure::read('facebook.app_id');
      $permissions = implode(',', Configure::read('facebook.permissions'));
      $redirect    = Router::url(false, true);
      $csrfToken   = CakeSession::read('FacebookAuthCSRF');

      $this->redirect(Configure::read('facebook.oauth_dialg_url') . '?client_id=' . $clientId . '&redirect_uri=' . $redirect . '&scope=' . $permissions . '&state=' . $csrfToken);
    } else {
      $this->redirect(array('action' => 'my_account'));
    }
  }

  public function my_account()
  {
    var_dump($this->Auth->user());
    die();
  }
}

挑战在于弄清楚如何让插件正常工作。


更新: 好的,我有这个网址(感谢 elliot):

http://someHost/?client_id=4003xx16796&redirect_uri=http://localhost/cake/users/login&scope=email&state=f96419881df77cdc689e6c43c131cf3b

现在,应该如何处理 url?下一步,基本上。我所拥有的只是一个登录按钮,当点击它时会更改 url,就像上面的演示一样,但没有任何操作。响应为空。

我已经阅读了this .

最佳答案

是问题

Configure::read('facebook.oauth_dialg_url')

应阅读:

Configure::read('facebook.oauth_dialog_url') 

还要确保您在 bootstrap.php 中执行了适当的 Configure::write 命令

Configure::write('facebook.oauth_dialog_url', 'http://some-value.com/path/to/url');

关于php - Oauth 认证 facebook - cakePHP 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11998747/

相关文章:

php - CakePHP:带有 saveMany 的未知列

javascript - PHP 脚本不返回查询,但 MySql 查询有效

android - Facebook SDK 4.5.0 在 android 中返回错误的用户 ID

javascript - Facebook 是如何检测到我的浏览器窗口需要关闭的?

android - 面子书 ://profile/{userid} seems to be not working

javascript - $http获取返回html源代码angularjs

php - CakePHP AclNode::node() - 找不到已识别的 Aro 节点

php - 在高流量网络应用程序中记录页面 View 的最佳解决方案

php - 在 PHP 中运行查询以显示在表中

javascript - 如何转义这个多维json数组/字符串