summaryrefslogtreecommitdiff
path: root/vendor/OAuth/OAuth1/Signature/Signature.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
committerFrédéric Guillot <fguillot@users.noreply.github.com>2014-05-03 22:24:03 -0400
commit560a12f0bd6347a335f8ed5201d6d9562d03d4bc (patch)
tree00510d25c1cf5e747573543fa88d44ef003b1c9a /vendor/OAuth/OAuth1/Signature/Signature.php
parent9531e439cd99fb7dbcfb039f422f1d1ba414ec30 (diff)
Add Google authentication
Diffstat (limited to 'vendor/OAuth/OAuth1/Signature/Signature.php')
-rwxr-xr-xvendor/OAuth/OAuth1/Signature/Signature.php132
1 files changed, 132 insertions, 0 deletions
diff --git a/vendor/OAuth/OAuth1/Signature/Signature.php b/vendor/OAuth/OAuth1/Signature/Signature.php
new file mode 100755
index 00000000..2e13eb37
--- /dev/null
+++ b/vendor/OAuth/OAuth1/Signature/Signature.php
@@ -0,0 +1,132 @@
+<?php
+
+namespace OAuth\OAuth1\Signature;
+
+use OAuth\Common\Consumer\CredentialsInterface;
+use OAuth\Common\Http\Uri\UriInterface;
+use OAuth\OAuth1\Signature\Exception\UnsupportedHashAlgorithmException;
+
+class Signature implements SignatureInterface
+{
+ /**
+ * @var Credentials
+ */
+ protected $credentials;
+
+ /**
+ * @var string
+ */
+ protected $algorithm;
+
+ /**
+ * @var string
+ */
+ protected $tokenSecret = null;
+
+ /**
+ * @param CredentialsInterface $credentials
+ */
+ public function __construct(CredentialsInterface $credentials)
+ {
+ $this->credentials = $credentials;
+ }
+
+ /**
+ * @param string $algorithm
+ */
+ public function setHashingAlgorithm($algorithm)
+ {
+ $this->algorithm = $algorithm;
+ }
+
+ /**
+ * @param string $token
+ */
+ public function setTokenSecret($token)
+ {
+ $this->tokenSecret = $token;
+ }
+
+ /**
+ * @param UriInterface $uri
+ * @param array $params
+ * @param string $method
+ *
+ * @return string
+ */
+ public function getSignature(UriInterface $uri, array $params, $method = 'POST')
+ {
+ parse_str($uri->getQuery(), $queryStringData);
+
+ foreach (array_merge($queryStringData, $params) as $key => $value) {
+ $signatureData[rawurlencode($key)] = rawurlencode($value);
+ }
+
+ ksort($signatureData);
+
+ // determine base uri
+ $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
+
+ if ('/' === $uri->getPath()) {
+ $baseUri .= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
+ } else {
+ $baseUri .= $uri->getPath();
+ }
+
+ $baseString = strtoupper($method) . '&';
+ $baseString .= rawurlencode($baseUri) . '&';
+ $baseString .= rawurlencode($this->buildSignatureDataString($signatureData));
+
+ return base64_encode($this->hash($baseString));
+ }
+
+ /**
+ * @param array $signatureData
+ *
+ * @return string
+ */
+ protected function buildSignatureDataString(array $signatureData)
+ {
+ $signatureString = '';
+ $delimiter = '';
+ foreach ($signatureData as $key => $value) {
+ $signatureString .= $delimiter . $key . '=' . $value;
+
+ $delimiter = '&';
+ }
+
+ return $signatureString;
+ }
+
+ /**
+ * @return string
+ */
+ protected function getSigningKey()
+ {
+ $signingKey = rawurlencode($this->credentials->getConsumerSecret()) . '&';
+ if ($this->tokenSecret !== null) {
+ $signingKey .= rawurlencode($this->tokenSecret);
+ }
+
+ return $signingKey;
+ }
+
+ /**
+ * @param string $data
+ *
+ * @return string
+ *
+ * @throws UnsupportedHashAlgorithmException
+ */
+ protected function hash($data)
+ {
+ switch (strtoupper($this->algorithm)) {
+ case 'HMAC-SHA1':
+ return hash_hmac('sha1', $data, $this->getSigningKey(), true);
+ default:
+ throw new UnsupportedHashAlgorithmException(
+ 'Unsupported hashing algorithm (' . $this->algorithm . ') used.'
+ );
+ }
+ }
+}