From 16804839127f54b54fc776a4fc5cbbc1f058570d Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 18 Jul 2009 18:07:30 -0400 Subject: [PATCH] Build authorization header, check for missing oauth_token and oauth_consumer_key Add method to Horde_Oauth_Request that builds an OAuth Authorization header (http://oauth.net/core/1.0#auth_header) Allow H_O_Request to obtain the *required* oauth_consumer_key and the oauth_token values from the Consumer and Token objects respectively so that client code doesn't have to awkardly pass them in both the Horde_Oauth_Consumer const'r and in the Horde_Oauth_Request const'r Add method to build an OAuth Authorization Header --- framework/Oauth/lib/Horde/Oauth/Request.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/framework/Oauth/lib/Horde/Oauth/Request.php b/framework/Oauth/lib/Horde/Oauth/Request.php index 2676e58f7..97991e563 100644 --- a/framework/Oauth/lib/Horde/Oauth/Request.php +++ b/framework/Oauth/lib/Horde/Oauth/Request.php @@ -39,8 +39,24 @@ class Horde_Oauth_Request $this->_url = $url; } + /** + * Sign this request in accordance with OAuth + * + * @param $signatureMethod + * @param $consumer + * @param $token + * @return unknown_type + */ public function sign($signatureMethod, $consumer, $token = null) { + if (empty($this->_params['oauth_consumer_key'])) { + $this->_params['oauth_consumer_key'] = $consumer->key; + } + + if (empty($this->_params['oauth_token']) && !is_null($token)) { + $this->_params['oauth_token'] = $token->key; + } + $this->_params['oauth_signature_method'] = $signatureMethod->getName(); $this->_params['oauth_signature'] = $signatureMethod->sign($this, $consumer, $token); @@ -76,6 +92,19 @@ class Horde_Oauth_Request return implode('&', $parts); } + public function buildAuthorizationHeader() + { + $header = ''; + var_dump($this->_params); + foreach ($this->_params as $k => $v) { + if (strpos($k, 'oauth_') !== false) { + $header .= Horde_Oauth_Utils::urlencodeRfc3986($k) . '="' . Horde_Oauth_Utils::urlencodeRfc3986($v) . '",'; + } + } + $header .= 'realm="' . Horde_Oauth_Utils::urlencodeRfc3986('twitter.com') . '"'; + return 'OAuth ' . $header; + } + /** * Generate a nonce. */ -- 2.11.0