11 Commits
1.0.1 ... 1.0.5

Author SHA1 Message Date
Eher
815a86af6e Alteração do psr-0 2012-04-03 11:00:41 -03:00
Eher
26a92abbdc Refactoring 2012-02-13 01:52:03 -02:00
Eher
2feec37a98 Composer.json updated 2012-02-12 15:39:42 -02:00
Eher
17ca454bb8 Composer.json updated 2012-02-12 15:17:48 -02:00
Eher
4344315960 Composer.json updated 2012-02-12 15:10:02 -02:00
Eher
0849d47418 psr-0 namespace configured 2012-02-12 13:39:28 -02:00
Eher
b1cea0857a Merge branch 'master' of github.com:EHER/OAuth
Conflicts:
	.gitignore
	composer.json
2012-02-09 13:03:36 -02:00
Eher
9d62ccdb86 Compuser json fixed 2012-02-09 08:33:29 -02:00
Eher
0efb3a5dfa Ignore some compuser and vim files 2012-02-09 08:33:01 -02:00
Eher
9cc377d653 SignatureMethod removed from namespace 2012-02-08 23:35:31 -02:00
Eher
67680e1564 Composer project data fixed 2012-02-08 22:44:20 -02:00
10 changed files with 41 additions and 47 deletions

2
.gitignore vendored
View File

@@ -1,3 +1,3 @@
*.swp
composer.lock
composer.phar
composer.lock

View File

@@ -1,18 +1,12 @@
{
"name": "Eher/OAuth",
"type": "library",
"description": "OAuth 1 PHP Library",
"keywords": ["oauth"],
"homepage": "https://github.com/EHER/OAuth",
"psr-0": {
"OAuth": "src/"
},
"authors":
{
"name": "Andy Smith",
"homepage": "http://term.ie/"
},
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Eher\\OAuth": "src"
}
}
}

View File

@@ -2,7 +2,7 @@
namespace Eher\OAuth;
class OAuthConsumer {
class Consumer {
public $key;
public $secret;

View File

@@ -1,6 +1,6 @@
<?php
namespace Eher\OAuth\SignatureMethod;
namespace Eher\OAuth;
/**
* The HMAC-SHA1 signature method uses the HMAC-SHA1 signature algorithm as defined in [RFC2104]
@@ -23,7 +23,7 @@ public function build_signature($request, $consumer, $token) {
($token) ? $token->secret : ""
);
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key_parts = Util::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
return base64_encode(hash_hmac('sha1', $base_string, $key, true));

View File

@@ -1,6 +1,6 @@
<?php
namespace Eher\OAuth\SignatureMethod;
namespace Eher\OAuth;
/**
* The PLAINTEXT method does not provide any security protection and SHOULD only be used
@@ -27,7 +27,7 @@ public function build_signature($request, $consumer, $token) {
($token) ? $token->secret : ""
);
$key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
$key_parts = Util::urlencode_rfc3986($key_parts);
$key = implode('&', $key_parts);
$request->base_string = $key;

View File

@@ -2,7 +2,7 @@
namespace Eher\OAuth;
class OAuthRequest {
class Request {
protected $parameters;
protected $http_method;
protected $http_url;
@@ -13,7 +13,7 @@ class OAuthRequest {
function __construct($http_method, $http_url, $parameters=NULL) {
$parameters = ($parameters) ? $parameters : array();
$parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$parameters = array_merge( Util::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters);
$this->parameters = $parameters;
$this->http_method = $http_method;
$this->http_url = $http_url;
@@ -40,10 +40,10 @@ public static function from_request($http_method=NULL, $http_url=NULL, $paramete
// parsed parameter-list
if (!$parameters) {
// Find request headers
$request_headers = OAuthUtil::get_headers();
$request_headers = Util::get_headers();
// Parse the query-string to find GET parameters
$parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
$parameters = Util::parse_parameters($_SERVER['QUERY_STRING']);
// It's a POST request of the proper content-type, so parse POST
// parameters and add those overriding any duplicates from GET
@@ -52,7 +52,7 @@ public static function from_request($http_method=NULL, $http_url=NULL, $paramete
&& strstr($request_headers['Content-Type'],
'application/x-www-form-urlencoded')
) {
$post_data = OAuthUtil::parse_parameters(
$post_data = Util::parse_parameters(
file_get_contents(self::$POST_INPUT)
);
$parameters = array_merge($parameters, $post_data);
@@ -61,7 +61,7 @@ public static function from_request($http_method=NULL, $http_url=NULL, $paramete
// We have a Authorization-header with OAuth data. Parse the header
// and add those overriding any duplicates from GET or POST
if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') {
$header_parameters = OAuthUtil::split_header(
$header_parameters = Util::split_header(
$request_headers['Authorization']
);
$parameters = array_merge($parameters, $header_parameters);
@@ -69,7 +69,7 @@ public static function from_request($http_method=NULL, $http_url=NULL, $paramete
}
return new OAuthRequest($http_method, $http_url, $parameters);
return new Request($http_method, $http_url, $parameters);
}
/**
@@ -77,16 +77,16 @@ public static function from_request($http_method=NULL, $http_url=NULL, $paramete
*/
public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) {
$parameters = ($parameters) ? $parameters : array();
$defaults = array("oauth_version" => OAuthRequest::$version,
"oauth_nonce" => OAuthRequest::generate_nonce(),
"oauth_timestamp" => OAuthRequest::generate_timestamp(),
$defaults = array("oauth_version" => Request::$version,
"oauth_nonce" => Request::generate_nonce(),
"oauth_timestamp" => Request::generate_timestamp(),
"oauth_consumer_key" => $consumer->key);
if ($token)
$defaults['oauth_token'] = $token->key;
$parameters = array_merge($defaults, $parameters);
return new OAuthRequest($http_method, $http_url, $parameters);
return new Request($http_method, $http_url, $parameters);
}
public function set_parameter($name, $value, $allow_duplicates = true) {
@@ -130,7 +130,7 @@ public function get_signable_parameters() {
unset($params['oauth_signature']);
}
return OAuthUtil::build_http_query($params);
return Util::build_http_query($params);
}
/**
@@ -147,7 +147,7 @@ public function get_signature_base_string() {
$this->get_signable_parameters()
);
$parts = OAuthUtil::urlencode_rfc3986($parts);
$parts = Util::urlencode_rfc3986($parts);
return implode('&', $parts);
}
@@ -194,7 +194,7 @@ public function to_url() {
* builds the data one would send in a POST request
*/
public function to_postdata() {
return OAuthUtil::build_http_query($this->parameters);
return Util::build_http_query($this->parameters);
}
/**
@@ -203,7 +203,7 @@ public function to_postdata() {
public function to_header($realm=null) {
$first = true;
if($realm) {
$out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"';
$out = 'Authorization: OAuth realm="' . Util::urlencode_rfc3986($realm) . '"';
$first = false;
} else
$out = 'Authorization: OAuth';
@@ -215,9 +215,9 @@ public function to_header($realm=null) {
throw new OAuthException('Arrays not supported in headers');
}
$out .= ($first) ? ' ' : ',';
$out .= OAuthUtil::urlencode_rfc3986($k) .
$out .= Util::urlencode_rfc3986($k) .
'="' .
OAuthUtil::urlencode_rfc3986($v) .
Util::urlencode_rfc3986($v) .
'"';
$first = false;
}

View File

@@ -1,6 +1,6 @@
<?php
namespace Eher\OAuth\SignatureMethod;
namespace Eher\OAuth;
/**
* A class for implementing a Signature Method

View File

@@ -1,8 +1,8 @@
<?php
namespace OAuth;
namespace Eher\OAuth;
class OAuthToken {
class Token {
// access tokens and request tokens
public $key;
public $secret;
@@ -22,9 +22,9 @@ function __construct($key, $secret) {
*/
function to_string() {
return "oauth_token=" .
OAuthUtil::urlencode_rfc3986($this->key) .
Util::urlencode_rfc3986($this->key) .
"&oauth_token_secret=" .
OAuthUtil::urlencode_rfc3986($this->secret);
Util::urlencode_rfc3986($this->secret);
}
function __toString() {

View File

@@ -1,11 +1,11 @@
<?php
namespace OAuth;
namespace Eher\OAuth;
class OAuthUtil {
class Util {
public static function urlencode_rfc3986($input) {
if (is_array($input)) {
return array_map(array('app\models\oauth\OAuthUtil', 'urlencode_rfc3986'), $input);
return array_map(array('Eher\OAuth\Util', 'urlencode_rfc3986'), $input);
} else if (is_scalar($input)) {
return str_replace(
'+',
@@ -34,7 +34,7 @@ public static function split_header($header, $only_allow_oauth_parameters = true
$params = array();
if (preg_match_all('/('.($only_allow_oauth_parameters ? 'oauth_' : '').'[a-z_-]*)=(:?"([^"]*)"|([^,]*))/', $header, $matches)) {
foreach ($matches[1] as $i => $h) {
$params[$h] = OAuthUtil::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
$params[$h] = Util::urldecode_rfc3986(empty($matches[3][$i]) ? $matches[4][$i] : $matches[3][$i]);
}
if (isset($params['realm'])) {
unset($params['realm']);
@@ -100,8 +100,8 @@ public static function parse_parameters( $input ) {
$parsed_parameters = array();
foreach ($pairs as $pair) {
$split = explode('=', $pair, 2);
$parameter = OAuthUtil::urldecode_rfc3986($split[0]);
$value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : '';
$parameter = Util::urldecode_rfc3986($split[0]);
$value = isset($split[1]) ? Util::urldecode_rfc3986($split[1]) : '';
if (isset($parsed_parameters[$parameter])) {
// We have already recieved parameter(s) with this name, so add to the list
@@ -125,8 +125,8 @@ public static function build_http_query($params) {
if (!$params) return '';
// Urlencode both keys and values
$keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
$values = OAuthUtil::urlencode_rfc3986(array_values($params));
$keys = Util::urlencode_rfc3986(array_keys($params));
$values = Util::urlencode_rfc3986(array_values($params));
$params = array_combine($keys, $values);
// Parameters are sorted by name, using lexicographical byte value ordering.