Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Signature.php
001 <?php
002 namespace OAuth\OAuth1\Signature;
003
004 use OAuth\Common\Consumer\Credentials;
005 use OAuth\Common\Http\Uri\UriInterface;
006 use OAuth\OAuth1\Signature\Exception\UnsupportedHashAlgorithmException;
007
008 class Signature implements SignatureInterface
009 {
010 /**
011 * @var \OAuth\Common\Consumer\Credentials
012 */
013 protected $credentials;
014
015 /**
016 * @var string
017 */
018 protected $algorithm;
019
020 /**
021 * @var string
022 */
023 protected $tokenSecret = null;
024
025 /**
026 * @param \OAuth\Common\Consumer\Credentials $credentials
027 */
028 public function __construct(Credentials $credentials)
029 {
030 $this->credentials = $credentials;
031 }
032
033 /**
034 * @param string $algorithm
035 */
036 public function setHashingAlgorithm($algorithm)
037 {
038 $this->algorithm = $algorithm;
039 }
040
041 /**
042 * @param string $token
043 */
044 public function setTokenSecret($token)
045 {
046 $this->tokenSecret = $token;
047 }
048
049 /**
050 * @param \OAuth\Common\Http\Uri\UriInterface $uri
051 * @param array $params
052 * @param string $method
053 * @return string
054 */
055 public function getSignature(UriInterface $uri, array $params, $method = 'POST')
056 {
057 parse_str($uri->getQuery(), $queryStringData);
058
059 foreach(array_merge($queryStringData, $params) as $key => $value) {
060 $signatureData[rawurlencode($key)] = rawurlencode($value);
061 }
062
063 ksort($signatureData);
064
065 // determine base uri
066 $baseUri = $uri->getScheme() . '://' . $uri->getRawAuthority();
067
068 if ('/' == $uri->getPath()) {
069 $baseUri.= $uri->hasExplicitTrailingHostSlash() ? '/' : '';
070 } else {
071 $baseUri .= $uri->getPath();
072 }
073
074 $baseString = strtoupper($method) . '&';
075 $baseString.= rawurlencode($baseUri) . '&';
076 $baseString.= rawurlencode($this->buildSignatureDataString($signatureData));
077
078 return base64_encode($this->hash($baseString));
079 }
080
081
082 /**
083 * @param array $signatureData
084 * @return string
085 */
086 protected function buildSignatureDataString(array $signatureData)
087 {
088 $signatureString = '';
089 $delimiter = '';
090 foreach($signatureData as $key => $value) {
091 $signatureString .= $delimiter . $key . '=' . $value;
092
093 $delimiter = '&';
094 }
095
096 return $signatureString;
097 }
098
099 /**
100 * @return string
101 */
102 protected function getSigningKey()
103 {
104 $signingKey = rawurlencode($this->credentials->getConsumerSecret()) . '&';
105 if ($this->tokenSecret !== null) {
106 $signingKey .= rawurlencode($this->tokenSecret);
107 }
108
109 return $signingKey;
110 }
111
112 /**
113 * @param string $data
114 * @return string
115 * @throws UnsupportedHashAlgorithmException
116 */
117 protected function hash($data)
118 {
119 switch(strtoupper($this->algorithm)) {
120 case 'HMAC-SHA1':
121 return hash_hmac('sha1', $data, $this->getSigningKey(), true);
122
123 default:
124 throw new UnsupportedHashAlgorithmException('Unsupported hashing algorithm (' . $this->algorithm . ') used.');
125 }
126 }
127 }
128