2013-03-01 4 views
0

Я пытаюсь реализовать плагин OAuth CakePHP здесь: https://github.com/seddonmedia/cakephp-oauth-serveropen_basedir с OAuth CakePHP плагин

Все, кажется, работает, как ожидается, до тех пор, когда пользователь принимает приложение не будет разрешено с 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')); 

}

Не уверен, что проблема ... Может кто-нибудь предложить какие-либо советы о том, что этот вопрос или как я мог исследовать дальше?

EDIT: Пробовал редактирования кода ниже на основании комментариев:

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); 
} 
+0

проверки файла: APP/Plugin/OAuth/Vendor/oauth2-PHP/Библиотека/OAuth2.php на линии 1064 и заменить 'file_get_contents ("/DEV/urandom ")' с 'mt_rand (0,99999999);' Таким образом, вам не нужно получать/dev/urandom, чтобы получить случайное число. –

+0

Пробовал, но просто получаю больше ошибок. И должен ли я редактировать Поставщика? Думал, что этот материал проверен и проверен. Проверьте мой OP для фрагмента кода, который я изменил. – Cameron

+0

Вы можете попросить своего хоста включить/dev/urandom в ваш open_basedir, который его решит. –

ответ

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); 
} 
+0

Ха-ха, да, понял это именно тогда. Но никогда бы не посмотрел на эту линию, если вы не прокомментировали выше. Спасибо за помощь ;) – Cameron