From 624e5ef2946fc7929eabdfd2e4d6516daa51f50b Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 18 Jul 2009 10:18:15 -0400 Subject: [PATCH] Documnet the required config parameters, throw exception if any are missing --- framework/Oauth/lib/Horde/Oauth/Consumer.php | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/framework/Oauth/lib/Horde/Oauth/Consumer.php b/framework/Oauth/lib/Horde/Oauth/Consumer.php index 154583a4d..045aaa97a 100644 --- a/framework/Oauth/lib/Horde/Oauth/Consumer.php +++ b/framework/Oauth/lib/Horde/Oauth/Consumer.php @@ -20,8 +20,29 @@ class Horde_Oauth_Consumer { protected $_config; + /** + * Const'r for consumer. + * + * @param array $config Configuration values: + *
+     *    'key'               - Consumer key
+     *    'secret'            - Consumer secret
+     *    'requestTokenUrl'   - The request token URL
+     *    'authorizeTokenUrl' - The authorize URL
+     *    'signatureMethod    - Horde_Oauth_SignatureMethod object
+     *  
+ * + * @return Horde_Oauth_Consumer + */ public function __construct($config) { + // Check for required config + if (!is_array($config) || empty($config['key']) || empty($config['secret']) || + empty($config['requestTokenUrl']) || empty($config['authorizeTokenUrl']) || + empty($config['signatureMethod'])) { + + throw new InvalidArgumentException('Missing a required parameter in Horde_Oauth_Consumer::__construct'); + } $this->_config = $config; } @@ -30,6 +51,13 @@ class Horde_Oauth_Consumer return isset($this->_config[$name]) ? $this->_config[$name] : null; } + /** + * Obtain a request token + * + * @param array $params Parameter array + * + * @return Horde_Oauth_Token A OAuth request token + */ public function getRequestToken($params = array()) { $params['oauth_consumer_key'] = $this->key; @@ -38,6 +66,7 @@ class Horde_Oauth_Consumer $request->sign($this->signatureMethod, $this); $client = new Horde_Http_Client; + $response = $client->post( $this->requestTokenUrl, $request->buildHttpQuery() @@ -45,11 +74,25 @@ class Horde_Oauth_Consumer return Horde_Oauth_Token::fromString($response->getBody()); } + /** + * Get the user authorization url + * + * @param Horde_Oauth_Token $token A OAuth token + * + * @return string The user authorization url string + */ public function getUserAuthorizationUrl($token) { return $this->authorizeTokenUrl . '?oauth_token=' . urlencode($token->key) . '&oauth_callback=' . urlencode($this->callbackUrl); } + /** + * + * @param Horde_Oauth_Token $token + * @param $params + * + * @return unknown_type + */ public function getAccessToken($token, $params = array()) { $params['oauth_consumer_key'] = $this->key; -- 2.11.0