OAuth CakePHP插件的open_basedir限制错误

时间:2013-03-01 23:24:28

标签: php cakephp

我正在尝试在此处实施OAuth CakePHP插件:https://github.com/seddonmedia/cakephp-oauth-server

在用户接受使用API​​授权的应用程序并发生以下错误之前,所有内容似乎都按预期工作:

Warning (2): file_exists() [function.file-exists]: open_basedir restriction in effect. File(/dev/urandom) is not within the allowed path(s): (/nfs:/tmp:/usr/local:/etc/apache2/gs-bin) [APP/Plugin/OAuth/Vendor/oauth2-php/lib/OAuth2.php, line 1064]
Warning (2): Cannot modify header information - headers already sent by (output started at /html/thirdparty/lib/Cake/Utility/Debugger.php:805) [APP/Plugin/OAuth/Vendor/oauth2-php/lib/OAuth2.php, line 945]
Warning (2): Cannot modify header information - headers already sent by (output started at /html/thirdparty/lib/Cake/Utility/Debugger.php:805) [APP/Plugin/OAuth/Vendor/oauth2-php/lib/OAuth2.php, line 946]

在错误发生之前调用的方法如下。

当用户点击“接受”时,它会发生在帖子上。

public function authorize(){

if (!$this->Auth->loggedIn()) {
    $this->redirect(array('action' => 'login', '?' => $this->request->query));
}

if ($this->request->is('post')) {
    $this->validateRequest();

    $userId = $this->Auth->user('id');

    if ($this->Session->check('OAuth.logout')) {
        $this->Auth->logout();
        $this->Session->delete('OAuth.logout');
    }

    //Did they accept the form? Adjust accordingly
    $accepted = $this->request->data['accept'] == 'Yep';
    try {
        $this->OAuth->finishClientAuthorization($accepted, $userId, $this->request->data['Authorize']);
    } catch (OAuth2RedirectException $e) {
        $e->sendHttpResponse();
    }
}

// Clickjacking prevention (supported by IE8+, FF3.6.9+, Opera10.5+, Safari4+, Chrome 4.1.249.1042+)
$this->response->header('X-Frame-Options: DENY');

if ($this->Session->check('OAuth.params')) {
        $OAuthParams = $this->Session->read('OAuth.params');
        $this->Session->delete('OAuth.params');
} else {
    try {
        $OAuthParams =  $this->OAuth->getAuthorizeParams();
    } catch (Exception $e){
        $e->sendHttpResponse();
    }
}
$this->set(compact('OAuthParams'));

}

不确定问题是什么......有人可以就问题是什么或我如何进一步调查提供任何建议吗?

编辑:尝试根据评论编辑以下代码:

protected function genAccessToken() {
    $tokenLen = 40;
    //if (file_exists('/dev/urandom')) { // Get 100 bytes of random data
    if(mt_rand(0,99999999)) {
        $randomData = file_get_contents('/dev/urandom', false, null, 0, 100) . uniqid(mt_rand(), true);
    } else {
        $randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);
    }
    return substr(hash('sha512', $randomData), 0, $tokenLen);
}

1 个答案:

答案 0 :(得分:1)

用此替换功能。这样你就不需要访问/ dev / urandom

protected function genAccessToken() {
    $tokenLen = 40;
    //if (file_exists('/dev/urandom')) { // Get 100 bytes of random data

        $randomData = mt_rand() . mt_rand() . mt_rand() . mt_rand() . microtime(true) . uniqid(mt_rand(), true);

    return substr(hash('sha512', $randomData), 0, $tokenLen);
}