Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of chaw.cakedc.com:oauth_lib
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed Apr 28, 2010
2 parents b7a5450 + 1ff7415 commit dc1f7de
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 29 deletions.
43 changes: 26 additions & 17 deletions libs/request_proxy/request_proxy_base.php
Expand Up @@ -228,7 +228,8 @@ public function xAuthParams() {
* @access public
*/
public function headerParams() {
$headers = array('X-HTTP_AUTHORIZATION', 'Authorization', 'HTTP_AUTHORIZATION', 'HTTP_HTTP_AUTHORIZATION', 'HTTP_X-HTTP_AUTHORIZATION');
$headers = array('X-HTTP_AUTHORIZATION', 'authorization', 'Authorization', 'HTTP_AUTHORIZATION', 'HTTP_HTTP_AUTHORIZATION', 'HTTP_X-HTTP_AUTHORIZATION');
$params = apache_request_headers();
foreach ($headers as $header) {
$header = env($header);
if (!$header) {
Expand All @@ -237,27 +238,35 @@ public function headerParams() {
if (substr($header, 0, 6) != 'OAuth ') {
continue;
}
$header = substr($header, 6, strlen($header));
$oauthParams = array();
$oauthParamString = preg_split('/[,]/', $header);
foreach ($oauthParamString as &$str) {
list($key, $value) = preg_split('/[=]/', $str);
$key = $this->unescape(trim($key));
$value = $this->unescape(trim($value));
$len = strlen($value);
if ((substr($value, 0, 1) == "\"") && (substr($value, $len-1, 1) == "\"")) {
$value = substr($value, 1, $len - 2);
}
if (substr($key, 0, 6) == 'oauth_') {
$oauthParams[$key] = $value;
}
return $this->_do($header);
}
foreach ($params as $k => $v) {
if (in_array($k, $headers)) {
return $this->_do($v);
}
ksort($oauthParams);
return $oauthParams;
}
return array();
}

protected function _do($header) {
$header = substr($header, 6, strlen($header));
$oauthParams = array();
$oauthParamString = preg_split('/[,]/', $header);
foreach ($oauthParamString as &$str) {
list($key, $value) = preg_split('/[=]/', $str);
$key = $this->unescape(trim($key));
$value = $this->unescape(trim($value));
$len = strlen($value);
if ((substr($value, 0, 1) == "\"") && (substr($value, $len-1, 1) == "\"")) {
$value = substr($value, 1, $len - 2);
}
if (substr($key, 0, 6) == 'oauth_') {
$oauthParams[$key] = $value;
}
}
ksort($oauthParams);
return $oauthParams;
}
/**
* Unescape wrapper
*
Expand Down
34 changes: 25 additions & 9 deletions oauth_lib_app_controller.php
Expand Up @@ -87,19 +87,35 @@ class OauthLibAppController extends AppController {
public function beforeFilter() {
if ($this->requireOAuth['enabled']) {
$this->_loadModels();
$actions = $this->requireOAuth['actions'];
if (is_array($actions) && (in_array($this->action, $actions) || in_array('*', $actions)) || $actions == '*') {
$this->verifyOauthRequest();
}
$this->configureOAuth();
$this->_afterOauthChecked();
} else {
parent::beforeFilter();
}
$actions = $this->requireOAuth['actions'];
if (is_array($actions) && (in_array($this->action, $actions) || in_array('*', $actions)) || $actions == '*') {
$this->verifyOauthRequest();

}
$this->configureOAuth();
return parent::beforeFilter();
}

/**
* load oauth server models callback
*
* @return void
* @access protected
*/
protected function _loadModels() {
$this->loadModel('ServerRegistry');
$this->loadModel('ServerToken');
// $this->loadModel('ServerRegistry');
// $this->loadModel('ServerToken');
}

/**
* after Oauth Checked callback
*
* @return void
* @access protected
*/
protected function _afterOauthChecked() {
}

/**
Expand Down
3 changes: 0 additions & 3 deletions vendors/shells/oauth.php
Expand Up @@ -294,9 +294,6 @@ public function query() {
}
$options = array(
'uri' => $this->options['uri'],
'access_token_uri' => $this->options['access_token_url'],
'authorize_uri' => $this->options['authorize_url'],
'request_token_uri' => $this->options['request_token_url'],
'scheme' => $this->options['scheme'],
'http_method' => $this->options['method']
);
Expand Down

0 comments on commit dc1f7de

Please sign in to comment.