0

我正在尝试在这里实现 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]

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

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

公共功能授权(){

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

1 回答 1

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);
}
于 2013-03-01T23:39:31.733 回答