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