move Horde_Oauth to git
authorChuck Hagenbuch <chuck@horde.org>
Sat, 15 Nov 2008 14:54:33 +0000 (09:54 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 15 Nov 2008 14:54:33 +0000 (09:54 -0500)
30 files changed:
framework/Oauth/CVS/Entries [new file with mode: 0644]
framework/Oauth/CVS/Repository [new file with mode: 0644]
framework/Oauth/CVS/Root [new file with mode: 0644]
framework/Oauth/CVS/Template [new file with mode: 0644]
framework/Oauth/lib/CVS/Entries [new file with mode: 0644]
framework/Oauth/lib/CVS/Repository [new file with mode: 0644]
framework/Oauth/lib/CVS/Root [new file with mode: 0644]
framework/Oauth/lib/CVS/Template [new file with mode: 0644]
framework/Oauth/lib/Horde/CVS/Entries [new file with mode: 0644]
framework/Oauth/lib/Horde/CVS/Repository [new file with mode: 0644]
framework/Oauth/lib/Horde/CVS/Root [new file with mode: 0644]
framework/Oauth/lib/Horde/CVS/Template [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/CVS/Entries [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/CVS/Repository [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/CVS/Root [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/CVS/Template [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/Consumer.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/Exception.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/Request.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/Base.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Entries [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Repository [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Root [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Template [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/HmacSha1.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/Plaintext.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/SignatureMethod/RsaSha1.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/Token.php [new file with mode: 0644]
framework/Oauth/lib/Horde/Oauth/Utils.php [new file with mode: 0644]
framework/Oauth/package.xml [new file with mode: 0644]

diff --git a/framework/Oauth/CVS/Entries b/framework/Oauth/CVS/Entries
new file mode 100644 (file)
index 0000000..dd51d51
--- /dev/null
@@ -0,0 +1,2 @@
+/package.xml/1.3/Tue Jul 29 05:00:09 2008//
+D/lib////
diff --git a/framework/Oauth/CVS/Repository b/framework/Oauth/CVS/Repository
new file mode 100644 (file)
index 0000000..c28bf52
--- /dev/null
@@ -0,0 +1 @@
+framework/Oauth
diff --git a/framework/Oauth/CVS/Root b/framework/Oauth/CVS/Root
new file mode 100644 (file)
index 0000000..5d63612
--- /dev/null
@@ -0,0 +1 @@
+chuck@cvs.horde.org:/repository
diff --git a/framework/Oauth/CVS/Template b/framework/Oauth/CVS/Template
new file mode 100644 (file)
index 0000000..3971591
--- /dev/null
@@ -0,0 +1,8 @@
+
+Bug: 
+Submitted by: 
+Merge after:
+CVS: ----------------------------------------------------------------------
+CVS: Bug:           Fill this in if a listed bug is affected by the change.
+CVS: Submitted by:  Fill this in if someone else sent in the change.
+CVS: Merge after:   N [day[s]|week[s]|month[s]] (days assumed by default)
diff --git a/framework/Oauth/lib/CVS/Entries b/framework/Oauth/lib/CVS/Entries
new file mode 100644 (file)
index 0000000..ae2779e
--- /dev/null
@@ -0,0 +1 @@
+D/Horde////
diff --git a/framework/Oauth/lib/CVS/Repository b/framework/Oauth/lib/CVS/Repository
new file mode 100644 (file)
index 0000000..99347cd
--- /dev/null
@@ -0,0 +1 @@
+framework/Oauth/lib
diff --git a/framework/Oauth/lib/CVS/Root b/framework/Oauth/lib/CVS/Root
new file mode 100644 (file)
index 0000000..5d63612
--- /dev/null
@@ -0,0 +1 @@
+chuck@cvs.horde.org:/repository
diff --git a/framework/Oauth/lib/CVS/Template b/framework/Oauth/lib/CVS/Template
new file mode 100644 (file)
index 0000000..3971591
--- /dev/null
@@ -0,0 +1,8 @@
+
+Bug: 
+Submitted by: 
+Merge after:
+CVS: ----------------------------------------------------------------------
+CVS: Bug:           Fill this in if a listed bug is affected by the change.
+CVS: Submitted by:  Fill this in if someone else sent in the change.
+CVS: Merge after:   N [day[s]|week[s]|month[s]] (days assumed by default)
diff --git a/framework/Oauth/lib/Horde/CVS/Entries b/framework/Oauth/lib/Horde/CVS/Entries
new file mode 100644 (file)
index 0000000..0a1f4ef
--- /dev/null
@@ -0,0 +1 @@
+D/Oauth////
diff --git a/framework/Oauth/lib/Horde/CVS/Repository b/framework/Oauth/lib/Horde/CVS/Repository
new file mode 100644 (file)
index 0000000..ccabea2
--- /dev/null
@@ -0,0 +1 @@
+framework/Oauth/lib/Horde
diff --git a/framework/Oauth/lib/Horde/CVS/Root b/framework/Oauth/lib/Horde/CVS/Root
new file mode 100644 (file)
index 0000000..5d63612
--- /dev/null
@@ -0,0 +1 @@
+chuck@cvs.horde.org:/repository
diff --git a/framework/Oauth/lib/Horde/CVS/Template b/framework/Oauth/lib/Horde/CVS/Template
new file mode 100644 (file)
index 0000000..3971591
--- /dev/null
@@ -0,0 +1,8 @@
+
+Bug: 
+Submitted by: 
+Merge after:
+CVS: ----------------------------------------------------------------------
+CVS: Bug:           Fill this in if a listed bug is affected by the change.
+CVS: Submitted by:  Fill this in if someone else sent in the change.
+CVS: Merge after:   N [day[s]|week[s]|month[s]] (days assumed by default)
diff --git a/framework/Oauth/lib/Horde/Oauth/CVS/Entries b/framework/Oauth/lib/Horde/Oauth/CVS/Entries
new file mode 100644 (file)
index 0000000..4f25354
--- /dev/null
@@ -0,0 +1,6 @@
+/Consumer.php/1.1/Tue Jul 29 03:25:15 2008//
+/Exception.php/1.1/Tue Jul 29 03:25:15 2008//
+/Request.php/1.1/Tue Jul 29 03:25:15 2008//
+/Token.php/1.1/Tue Jul 29 03:25:15 2008//
+/Utils.php/1.1/Tue Jul 29 03:25:15 2008//
+D/SignatureMethod////
diff --git a/framework/Oauth/lib/Horde/Oauth/CVS/Repository b/framework/Oauth/lib/Horde/Oauth/CVS/Repository
new file mode 100644 (file)
index 0000000..716193b
--- /dev/null
@@ -0,0 +1 @@
+framework/Oauth/lib/Horde/Oauth
diff --git a/framework/Oauth/lib/Horde/Oauth/CVS/Root b/framework/Oauth/lib/Horde/Oauth/CVS/Root
new file mode 100644 (file)
index 0000000..5d63612
--- /dev/null
@@ -0,0 +1 @@
+chuck@cvs.horde.org:/repository
diff --git a/framework/Oauth/lib/Horde/Oauth/CVS/Template b/framework/Oauth/lib/Horde/Oauth/CVS/Template
new file mode 100644 (file)
index 0000000..3971591
--- /dev/null
@@ -0,0 +1,8 @@
+
+Bug: 
+Submitted by: 
+Merge after:
+CVS: ----------------------------------------------------------------------
+CVS: Bug:           Fill this in if a listed bug is affected by the change.
+CVS: Submitted by:  Fill this in if someone else sent in the change.
+CVS: Merge after:   N [day[s]|week[s]|month[s]] (days assumed by default)
diff --git a/framework/Oauth/lib/Horde/Oauth/Consumer.php b/framework/Oauth/lib/Horde/Oauth/Consumer.php
new file mode 100644 (file)
index 0000000..97cadf2
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth consumer class
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_Consumer
+{
+    protected $_config;
+
+    public function __construct($config)
+    {
+        $this->_config = $config;
+    }
+
+    public function __get($name)
+    {
+        return isset($this->_config[$name]) ? $this->_config[$name] : null;
+    }
+
+    public function getRequestToken($params = array())
+    {
+        $params['oauth_consumer_key'] = $this->key;
+
+        $request = new Horde_Oauth_Request($this->requestTokenUrl, $params);
+        $request->sign($this->signatureMethod, $this);
+
+        $client = new Horde_Http_Client;
+        $response = $client->post(
+            $this->requestTokenUrl,
+            $request->buildHttpQuery()
+        );
+        return Horde_Oauth_Token::fromString($response->getBody());
+    }
+
+    public function getUserAuthorizationUrl($token)
+    {
+        return $this->authorizeTokenUrl . '?oauth_token=' . urlencode($token->key) . '&oauth_callback=' . urlencode($this->callbackUrl);
+    }
+
+    public function getAccessToken($token, $params = array())
+    {
+        $params['oauth_consumer_key'] = $this->key;
+        $params['oauth_token'] = $token->key;
+
+        $request = new Horde_Oauth_Request($this->accessTokenUrl, $params);
+        $request->sign($this->signatureMethod, $this, $token);
+
+        $client = new Horde_Http_Client;
+        $response = $client->post(
+            $this->accessTokenUrl,
+            $request->buildHttpQuery()
+        );
+        return Horde_Oauth_Token::fromString($response->getBody());
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/Exception.php b/framework/Oauth/lib/Horde/Oauth/Exception.php
new file mode 100644 (file)
index 0000000..677b60e
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth exception class
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_Exception extends Exception
+{
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/Request.php b/framework/Oauth/lib/Horde/Oauth/Request.php
new file mode 100644 (file)
index 0000000..2f53d9a
--- /dev/null
@@ -0,0 +1,137 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth request class
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_Request
+{
+    const VERSION = '1.0';
+
+    protected $_params = array();
+    protected $_url;
+
+    function __construct($url, $params = array())
+    {
+        if (!isset($params['oauth_version'])) {
+            $params['oauth_version'] = self::VERSION;
+        }
+        if (!isset($params['oauth_nonce'])) {
+            $params['oauth_nonce'] = self::_generateNonce();
+        }
+        if (!isset($params['oauth_timestamp'])) {
+            $params['oauth_timestamp'] = time();
+        }
+
+        $this->_params = $params;
+        $this->_url = $url;
+    }
+
+    public function sign($signatureMethod, $consumer, $token = null)
+    {
+        $this->_params['oauth_signature_method'] = $signatureMethod->getName();
+        $this->_params['oauth_signature'] = $signatureMethod->sign($this, $consumer, $token);
+
+        return $this->_url . '?' . $this->buildHttpQuery();
+    }
+
+    /**
+     * Returns the signable string of this request
+     *
+     * The base string is defined as the method, the url and the parameters
+     * (normalized), each urlencoded and concatenated with &.
+     */
+    public function getSignatureBaseString()
+    {
+        $parts = array(
+            'POST',
+            $this->_url,
+            $this->_getSignableParameters()
+        );
+
+        return implode('&', array_map(array('Horde_Oauth_Utils', 'urlencodeRfc3986'), $parts));
+    }
+
+    /**
+     * Get a query string suitable for use in a URL or as POST data.
+     */
+    public function buildHttpQuery()
+    {
+        $parts = array();
+        foreach ($this->_params as $k => $v) {
+            $parts[] = Horde_Oauth_Utils::urlencodeRfc3986($k) . '=' . Horde_Oauth_Utils::urlencodeRfc3986($v);
+        }
+        return implode('&', $parts);
+    }
+
+    /**
+     * Generate a nonce.
+     */
+    protected static function _generateNonce()
+    {
+        $mt = microtime();
+        $rand = mt_rand();
+
+        return md5(microtime() . mt_rand());
+    }
+
+    /**
+     * Returns the normalized parameters of the request
+     *
+     * This will be all parameters except oauth_signature, sorted first by key,
+     * and if there are duplicate keys, then by value.
+     *
+     * The returned string will be all the key=value pairs concatenated by &.
+     *
+     * @return string
+     */
+    protected function _getSignableParameters()
+    {
+        // Grab all parameters
+        $params = $this->_params;
+
+        // Remove oauth_signature if present
+        if (isset($params['oauth_signature'])) {
+            unset($params['oauth_signature']);
+        }
+
+        // Urlencode both keys and values
+        $keys = array_map(array('Horde_Oauth_Utils', 'urlencodeRfc3986'), array_keys($params));
+        $values = array_map(array('Horde_Oauth_Utils', 'urlencodeRfc3986'), array_values($params));
+        $params = array_combine($keys, $values);
+
+        // Sort by keys (natsort)
+        uksort($params, 'strnatcmp');
+
+        // Generate key=value pairs
+        $pairs = array();
+        foreach ($params as $key => $value) {
+            if (is_array($value)) {
+                // If the value is an array, it's because there are multiple values
+                // with the same key. Sort them, then add all the pairs.
+                natsort($value);
+                foreach ($value as $v2) {
+                    $pairs[] = $key . '=' . $v2;
+                }
+            } else {
+                $pairs[] = $key . '=' . $value;
+            }
+        }
+
+        // Return the pairs, concatenated with &
+        return implode('&', $pairs);
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/Base.php b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/Base.php
new file mode 100644 (file)
index 0000000..b1a4e96
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth abstract signature method base class
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+abstract class Horde_Oauth_SignatureMethod_Base
+{
+    abstract public function getName();
+
+    abstract public function sign($request, $consumer, $token);
+
+    public function verify($signature, $request, $consumer, $token)
+    {
+        return $signature == $this->sign($request, $consumer, $token);
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Entries b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Entries
new file mode 100644 (file)
index 0000000..d8a0c00
--- /dev/null
@@ -0,0 +1,5 @@
+/Base.php/1.1/Tue Jul 29 03:25:16 2008//
+/HmacSha1.php/1.1/Tue Jul 29 03:25:16 2008//
+/Plaintext.php/1.1/Tue Jul 29 03:25:16 2008//
+/RsaSha1.php/1.1/Tue Jul 29 03:25:16 2008//
+D
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Repository b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Repository
new file mode 100644 (file)
index 0000000..d04a3a6
--- /dev/null
@@ -0,0 +1 @@
+framework/Oauth/lib/Horde/Oauth/SignatureMethod
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Root b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Root
new file mode 100644 (file)
index 0000000..5d63612
--- /dev/null
@@ -0,0 +1 @@
+chuck@cvs.horde.org:/repository
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Template b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/CVS/Template
new file mode 100644 (file)
index 0000000..3971591
--- /dev/null
@@ -0,0 +1,8 @@
+
+Bug: 
+Submitted by: 
+Merge after:
+CVS: ----------------------------------------------------------------------
+CVS: Bug:           Fill this in if a listed bug is affected by the change.
+CVS: Submitted by:  Fill this in if someone else sent in the change.
+CVS: Merge after:   N [day[s]|week[s]|month[s]] (days assumed by default)
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/HmacSha1.php b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/HmacSha1.php
new file mode 100644 (file)
index 0000000..177be9b
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth HMAC-SHA1 signature method
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_SignatureMethod_HmacSha1 extends Horde_Oauth_SignatureMethod_Base
+{
+    public function getName()
+    {
+        return 'HMAC-SHA1';
+    }
+
+    public function sign($request, $consumer, $token)
+    {
+        $baseString = $request->getSignatureBaseString();
+
+        $key_parts = array(
+            $consumer->secret,
+            ($token) ? $token->secret : ''
+        );
+
+        $key_parts = array_map(array('Horde_Oauth_Utils','urlencodeRfc3986'), $key_parts);
+        $key = implode('&', $key_parts);
+
+        return base64_encode(hash_hmac('sha1', $baseString, $key, true));
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/Plaintext.php b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/Plaintext.php
new file mode 100644 (file)
index 0000000..4f0abc5
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth plaintext signature method
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_SignatureMethod_Plaintext extends Horde_Oauth_SignatureMethod_Base
+{
+    public function getName()
+    {
+        return 'PLAINTEXT';
+    }
+
+    public function sign($request, $consumer, $token)
+    {
+        $signature = array(
+            Horde_Oauth_Utils::urlencodeRfc3986($consumer->secret),
+        );
+
+        if ($token) {
+            array_push($signature, Horde_Oauth_Utils::urlencodeRfc3986($token->secret));
+        } else {
+            array_push($signature, '');
+        }
+
+        return Horde_Oauth_Utils::urlencodeRfc3986(implode('&', $signature));
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/SignatureMethod/RsaSha1.php b/framework/Oauth/lib/Horde/Oauth/SignatureMethod/RsaSha1.php
new file mode 100644 (file)
index 0000000..7bcf108
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth RSA-SHA1 signature method
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_SignatureMethod_RsaSha1 extends Horde_Oauth_SignatureMethod_Base
+{
+    public function __construct($publicKey = null, $privateKey = null)
+    {
+        $this->_publicKey = $publicKey;
+        $this->_privateKey = $privateKey;
+    }
+
+    public function getName()
+    {
+        return 'RSA-SHA1';
+    }
+
+    public function sign($request, $consumer, $token)
+    {
+        $baseString = $request->getSignatureBaseString();
+
+        $pkeyid = openssl_pkey_get_private($this->_privateKey);
+        $ok = openssl_sign($baseString, $signature, $pkeyid);
+        openssl_free_key($pkeyid);
+
+        return base64_encode($signature);
+    }
+
+    public function verify($signature, $request, $consumer, $token)
+    {
+        $decodedSignature = base64_decode($signature);
+        $baseString = $request->getSignatureBaseString();
+
+        $pubkeyid = openssl_pkey_get_public($this->_publicKey);
+        $result = openssl_verify($baseString, $decodedSignature, $pubkeyid);
+        openssl_free_key($pubkeyid);
+
+        return $result == 1;
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/Token.php b/framework/Oauth/lib/Horde/Oauth/Token.php
new file mode 100644 (file)
index 0000000..e43825f
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth access tokens and request tokens
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_Token
+{
+    public $key;
+    public $secret;
+
+    /**
+     * key = the token
+     * secret = the token secret
+     */
+    function __construct($key, $secret)
+    {
+        $this->key = $key;
+        $this->secret = $secret;
+    }
+
+    /**
+     * Generate the basic string serialization of a token that a server would
+     * respond to request_token and access_token calls with.
+     */
+    public function __toString()
+    {
+        return
+            'oauth_token='.Horde_Oauth_Utils::urlencodeRfc3986($this->key).
+            '&oauth_token_secret='.Horde_Oauth_Utils::urlencodeRfc3986($this->secret);
+    }
+
+    public static function fromString($string)
+    {
+        parse_str($string, $parts);
+        return new self($parts['oauth_token'], $parts['oauth_token_secret']);
+    }
+
+}
diff --git a/framework/Oauth/lib/Horde/Oauth/Utils.php b/framework/Oauth/lib/Horde/Oauth/Utils.php
new file mode 100644 (file)
index 0000000..d0638df
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * Copyright 2008 The Horde Project (http://www.horde.org/)
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+
+/**
+ * OAuth utilities
+ *
+ * @author   Chuck Hagenbuch <chuck@horde.org>
+ * @license  http://opensource.org/licenses/bsd-license.php BSD
+ * @category Horde
+ * @package  Horde_Oauth
+ */
+class Horde_Oauth_Utils
+{
+    public static function urlencodeRfc3986($string)
+    {
+        return str_replace(array('%7E', '+'),
+                           array('~', '%20'),
+                           rawurlencode($string));
+    }
+
+}
diff --git a/framework/Oauth/package.xml b/framework/Oauth/package.xml
new file mode 100644 (file)
index 0000000..4cfcfb5
--- /dev/null
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Oauth</name>
+ <channel>pear.horde.org</channel>
+ <summary>Horde OAuth client/server</summary>
+ <description>This package provides an OAuth consumer (http://oauth.net) and OAuth infrastruture, and in the future will provide an OAuth server.
+ </description>
+ <lead>
+  <name>Chuck Hagenbuch</name>
+  <user>chuck</user>
+  <email>chuck@horde.org</email>
+  <active>yes</active>
+ </lead>
+ <date>2008-07-28</date>
+ <version>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
+ </version>
+ <stability>
+  <release>beta</release>
+  <api>beta</api>
+ </stability>
+ <license uri="http://opensource.org/licenses/bsd-license.php">BSD</license>
+ <notes>
+* Initial release
+ </notes>
+ <contents>
+  <dir name="/">
+   <dir name="lib">
+    <dir name="Horde">
+     <dir name="Oauth">
+      <dir name="SignatureMethod">
+       <file name="Base.php" role="php" />
+       <file name="HmacSha1.php" role="php" />
+       <file name="Plaintext.php" role="php" />
+       <file name="RsaSha1.php" role="php" />
+      </dir> <!-- /lib/Horde/Oauth/SignatureMethod -->
+      <file name="Consumer.php" role="php" />
+      <file name="Exception.php" role="php" />
+      <file name="Request.php" role="php" />
+      <file name="Token.php" role="php" />
+      <file name="Utils.php" role="php" />
+     </dir> <!-- /lib/Horde/Oauth -->
+    </dir> <!-- /lib/Horde -->
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.2.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.5.0</min>
+   </pearinstaller>
+   <package>
+    <name>Http_Client</name>
+    <channel>pear.horde.org</channel>
+   </package>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install name="lib/Horde/Oauth/Consumer.php" as="Horde/Oauth/Consumer.php" />
+   <install name="lib/Horde/Oauth/Exception.php" as="Horde/Oauth/Exception.php" />
+   <install name="lib/Horde/Oauth/Request.php" as="Horde/Oauth/Request.php" />
+   <install name="lib/Horde/Oauth/SignatureMethod/Base.php" as="Horde/Oauth/SignatureMethod/Base.php" />
+   <install name="lib/Horde/Oauth/SignatureMethod/HmacSha1.php" as="Horde/Oauth/SignatureMethod/HmacSha1.php" />
+   <install name="lib/Horde/Oauth/SignatureMethod/Plaintext.php" as="Horde/Oauth/SignatureMethod/Plaintext.php" />
+   <install name="lib/Horde/Oauth/SignatureMethod/RsaSha1.php" as="Horde/Oauth/SignatureMethod/RsaSha1.php" />
+   <install name="lib/Horde/Oauth/Token.php" as="Horde/Oauth/Token.php" />
+   <install name="lib/Horde/Oauth/Utils.php" as="Horde/Oauth/Utils.php" />
+  </filelist>
+ </phprelease>
+</package>