diff --git a/src/MaxCDN/OAuth/OAuthConsumer.php b/src/MaxCDN/OAuth/OAuthConsumer.php index b016369..b3d126d 100644 --- a/src/MaxCDN/OAuth/OAuthConsumer.php +++ b/src/MaxCDN/OAuth/OAuthConsumer.php @@ -4,17 +4,20 @@ */ namespace MaxCDN\OAuth; -class OAuthConsumer { +class OAuthConsumer +{ public $key; public $secret; - function __construct($key, $secret, $callback_url=NULL) { + function __construct($key, $secret, $callback_url=NULL) + { $this->key = $key; $this->secret = $secret; $this->callback_url = $callback_url; } - function __toString() { + function __toString() + { return "\\MaxCDN\\OAuth\\OAuthConsumer[key=$this->key,secret=$this->secret]"; } } diff --git a/src/MaxCDN/OAuth/OAuthDataStore.php b/src/MaxCDN/OAuth/OAuthDataStore.php index c3fb037..248c289 100644 --- a/src/MaxCDN/OAuth/OAuthDataStore.php +++ b/src/MaxCDN/OAuth/OAuthDataStore.php @@ -1,24 +1,30 @@ <?php namespace MaxCDN\OAuth; -class OAuthDataStore { - function lookup_consumer($consumer_key) { +class OAuthDataStore +{ + function lookup_consumer($consumer_key) + { // implement me } - function lookup_token($consumer, $token_type, $token) { + function lookup_token($consumer, $token_type, $token) + { // implement me } - function lookup_nonce($consumer, $token, $nonce, $timestamp) { + function lookup_nonce($consumer, $token, $nonce, $timestamp) + { // implement me } - function new_request_token($consumer, $callback = null) { + function new_request_token($consumer, $callback = null) + { // return a new token attached to this consumer } - function new_access_token($token, $consumer, $verifier = null) { + function new_access_token($token, $consumer, $verifier = null) + { // return a new access token attached to this consumer // for the user associated with this token if the request token // is authorized diff --git a/src/MaxCDN/OAuth/OAuthException.php b/src/MaxCDN/OAuth/OAuthException.php index 7ab4ded..ca156b2 100644 --- a/src/MaxCDN/OAuth/OAuthException.php +++ b/src/MaxCDN/OAuth/OAuthException.php @@ -4,7 +4,7 @@ */ namespace MaxCDN\OAuth; -class OAuthException extends Exception { +class OAuthException extends Exception +{ // pass } - diff --git a/src/MaxCDN/OAuth/OAuthSignatureMethod.php b/src/MaxCDN/OAuth/OAuthSignatureMethod.php index da905ff..bdd9264 100644 --- a/src/MaxCDN/OAuth/OAuthSignatureMethod.php +++ b/src/MaxCDN/OAuth/OAuthSignatureMethod.php @@ -5,7 +5,8 @@ */ namespace MaxCDN\OAuth; -abstract class OAuthSignatureMethod { +abstract class OAuthSignatureMethod +{ /** * Needs to return the name of the Signature Method (ie HMAC-SHA1) * @return string @@ -32,7 +33,8 @@ abstract public function build_signature($request, $consumer, $token); * @param string $signature * @return bool */ - public function check_signature($request, $consumer, $token, $signature) { + public function check_signature($request, $consumer, $token, $signature) + { $built = $this->build_signature($request, $consumer, $token); // Check for zero length, although unlikely here @@ -53,4 +55,3 @@ public function check_signature($request, $consumer, $token, $signature) { return $result == 0; } } - diff --git a/src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php b/src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php index 5f413cc..32e29ec 100644 --- a/src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php +++ b/src/MaxCDN/OAuth/OAuthSignatureMethod_HMAC_SHA1.php @@ -8,24 +8,26 @@ */ namespace MaxCDN\OAuth; -class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { - function get_name() { - return "HMAC-SHA1"; - } +class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod +{ + function get_name() + { + return "HMAC-SHA1"; + } - public function build_signature($request, $consumer, $token) { - $base_string = $request->get_signature_base_string(); - $request->base_string = $base_string; + public function build_signature($request, $consumer, $token) + { + $base_string = $request->get_signature_base_string(); + $request->base_string = $base_string; - $key_parts = array( - $consumer->secret, - ($token) ? $token->secret : "" - ); + $key_parts = array( + $consumer->secret, + ($token) ? $token->secret : "" + ); - $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); - $key = implode('&', $key_parts); + $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); + $key = implode('&', $key_parts); - return base64_encode(hash_hmac('sha1', $base_string, $key, true)); - } + return base64_encode(hash_hmac('sha1', $base_string, $key, true)); + } } - diff --git a/src/MaxCDN/OAuth/OAuthSignatureMethod_PLAINTEXT.php b/src/MaxCDN/OAuth/OAuthSignatureMethod_PLAINTEXT.php index 41e1232..bba0631 100644 --- a/src/MaxCDN/OAuth/OAuthSignatureMethod_PLAINTEXT.php +++ b/src/MaxCDN/OAuth/OAuthSignatureMethod_PLAINTEXT.php @@ -7,21 +7,24 @@ namespace MaxCDN\OAuth; -class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { - public function get_name() { +class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod +{ + public function get_name() + { return "PLAINTEXT"; } /** - * oauth_signature is set to the concatenated encoded values of the Consumer Secret and - * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is + * oauth_signature is set to the concatenated encoded values of the Consumer Secret and + * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is * empty. The result MUST be encoded again. * - Chapter 9.4.1 ("Generating Signatures") * * Please note that the second encoding MUST NOT happen in the SignatureMethod, as * OAuthRequest handles this! */ - public function build_signature($request, $consumer, $token) { + public function build_signature($request, $consumer, $token) + { $key_parts = array( $consumer->secret, ($token) ? $token->secret : "" @@ -34,4 +37,3 @@ public function build_signature($request, $consumer, $token) { return $key; } } - diff --git a/src/MaxCDN/OAuth/OAuthSignatureMethod_RSA_SHA1.php b/src/MaxCDN/OAuth/OAuthSignatureMethod_RSA_SHA1.php index ddd7bf9..d9a4671 100644 --- a/src/MaxCDN/OAuth/OAuthSignatureMethod_RSA_SHA1.php +++ b/src/MaxCDN/OAuth/OAuthSignatureMethod_RSA_SHA1.php @@ -9,8 +9,10 @@ */ namespace MaxCDN\OAuth; -abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { - public function get_name() { +abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod +{ + public function get_name() + { return "RSA-SHA1"; } @@ -20,15 +22,16 @@ public function get_name() { // (3) some sort of specific discovery code based on request // // Either way should return a string representation of the certificate - protected abstract function fetch_public_cert(&$request); + abstract protected function fetch_public_cert(&$request); // Up to the SP to implement this lookup of keys. Possible ideas are: // (1) do a lookup in a table of trusted certs keyed off of consumer // // Either way should return a string representation of the certificate - protected abstract function fetch_private_cert(&$request); + abstract protected function fetch_private_cert(&$request); - public function build_signature($request, $consumer, $token) { + public function build_signature($request, $consumer, $token) + { $base_string = $request->get_signature_base_string(); $request->base_string = $base_string; @@ -47,7 +50,8 @@ public function build_signature($request, $consumer, $token) { return base64_encode($signature); } - public function check_signature($request, $consumer, $token, $signature) { + public function check_signature($request, $consumer, $token, $signature) + { $decoded_sig = base64_decode($signature); $base_string = $request->get_signature_base_string(); @@ -67,4 +71,3 @@ public function check_signature($request, $consumer, $token, $signature) { return $ok == 1; } } - diff --git a/src/MaxCDN/OAuth/OAuthToken.php b/src/MaxCDN/OAuth/OAuthToken.php index 4c852eb..693a268 100644 --- a/src/MaxCDN/OAuth/OAuthToken.php +++ b/src/MaxCDN/OAuth/OAuthToken.php @@ -4,7 +4,8 @@ */ namespace MaxCDN\OAuth; -class OAuthToken { +class OAuthToken +{ // access tokens and request tokens public $key; public $secret; @@ -13,7 +14,8 @@ class OAuthToken { * key = the token * secret = the token secret */ - function __construct($key, $secret) { + function __construct($key, $secret) + { $this->key = $key; $this->secret = $secret; } @@ -22,15 +24,16 @@ function __construct($key, $secret) { * generates the basic string serialization of a token that a server * would respond to request_token and access_token calls with */ - function to_string() { + function to_string() + { return "oauth_token=" . OAuthUtil::urlencode_rfc3986($this->key) . "&oauth_token_secret=" . OAuthUtil::urlencode_rfc3986($this->secret); } - function __toString() { + function __toString() + { return $this->to_string(); } } - diff --git a/src/MaxCDN/OAuth/OAuthUtil.php b/src/MaxCDN/OAuth/OAuthUtil.php index ac0dff6..4733742 100644 --- a/src/MaxCDN/OAuth/OAuthUtil.php +++ b/src/MaxCDN/OAuth/OAuthUtil.php @@ -1,16 +1,18 @@ <?php namespace MaxCDN\OAuth; -class OAuthUtil { - public static function urlencode_rfc3986($input) { +class OAuthUtil +{ + public static function urlencode_rfc3986($input) + { if (is_array($input)) { return array_map(array('\MaxCDN\OAuth\OAuthUtil', 'urlencode_rfc3986'), $input); } else if (is_scalar($input)) { return str_replace( - '+', - ' ', - str_replace('%7E', '~', rawurlencode($input)) - ); + '+', + ' ', + str_replace('%7E', '~', rawurlencode($input)) + ); } else { return ''; } @@ -20,7 +22,8 @@ public static function urlencode_rfc3986($input) { // This decode function isn't taking into consideration the above // modifications to the encoding process. However, this method doesn't // seem to be used anywhere so leaving it as is. - public static function urldecode_rfc3986($string) { + public static function urldecode_rfc3986($string) + { return urldecode($string); } @@ -29,21 +32,23 @@ public static function urldecode_rfc3986($string) { // Can filter out any non-oauth parameters if needed (default behaviour) // May 28th, 2010 - method updated to tjerk.meesters for a speed improvement. // see http://code.google.com/p/oauth/issues/detail?id=163 - public static function split_header($header, $only_allow_oauth_parameters = true) { + 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]); } - if (isset($params['realm'])) { - unset($params['realm']); + if (isset($params['realm'])) { + unset($params['realm']); + } } - } - return $params; + return $params; } // helper to try to sort out headers for people who aren't running apache - public static function get_headers() { + public static function get_headers() + { if (function_exists('apache_request_headers')) { // we need this to get the actual Authorization: header // because apache tends to tell us it doesn't exist @@ -56,10 +61,10 @@ public static function get_headers() { $out = array(); foreach ($headers AS $key => $value) { $key = str_replace( - " ", - "-", - ucwords(strtolower(str_replace("-", " ", $key))) - ); + " ", + "-", + ucwords(strtolower(str_replace("-", " ", $key))) + ); $out[$key] = $value; } } else { @@ -77,10 +82,10 @@ public static function get_headers() { // letter of every word that is not an initial HTTP and strip HTTP // code from przemek $key = str_replace( - " ", - "-", - ucwords(strtolower(str_replace("_", " ", substr($key, 5)))) - ); + " ", + "-", + ucwords(strtolower(str_replace("_", " ", substr($key, 5)))) + ); $out[$key] = $value; } } @@ -91,7 +96,8 @@ public static function get_headers() { // This function takes a input like a=b&a=c&d=e and returns the parsed // parameters like this // array('a' => array('b','c'), 'd' => 'e') - public static function parse_parameters( $input ) { + public static function parse_parameters( $input ) + { if (!isset($input) || !$input) return array(); $pairs = explode('&', $input); @@ -120,7 +126,8 @@ public static function parse_parameters( $input ) { return $parsed_parameters; } - public static function build_http_query($params) { + public static function build_http_query($params) + { if (!$params) return ''; // Urlencode both keys and values @@ -151,4 +158,3 @@ public static function build_http_query($params) { return implode('&', $pairs); } } -