|
3 | 3 | namespace League\OAuth1\Client\Server;
|
4 | 4 |
|
5 | 5 | use League\OAuth1\Client\Credentials\TokenCredentials;
|
| 6 | +use League\OAuth1\Client\Signature\SignatureInterface; |
6 | 7 |
|
7 | 8 | class Twitter extends Server
|
8 | 9 | {
|
| 10 | + /** |
| 11 | + * Application scope. |
| 12 | + * |
| 13 | + * @var string |
| 14 | + */ |
| 15 | + protected $applicationScope; |
| 16 | + |
| 17 | + /** |
| 18 | + * @inheritDoc |
| 19 | + */ |
| 20 | + public function __construct($clientCredentials, SignatureInterface $signature = null) |
| 21 | + { |
| 22 | + parent::__construct($clientCredentials, $signature); |
| 23 | + |
| 24 | + if (is_array($clientCredentials)) { |
| 25 | + $this->parseConfiguration($clientCredentials); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Set the application scope. |
| 31 | + * |
| 32 | + * @param string $applicationScope |
| 33 | + * |
| 34 | + * @return Twitter |
| 35 | + */ |
| 36 | + public function setApplicationScope($applicationScope) |
| 37 | + { |
| 38 | + $this->applicationScope = $applicationScope; |
| 39 | + |
| 40 | + return $this; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Get application scope. |
| 45 | + * |
| 46 | + * @return string |
| 47 | + */ |
| 48 | + public function getApplicationScope() |
| 49 | + { |
| 50 | + return $this->applicationScope ?: 'read'; |
| 51 | + } |
| 52 | + |
9 | 53 | /**
|
10 | 54 | * @inheritDoc
|
11 | 55 | */
|
@@ -97,4 +141,34 @@ public function userScreenName($data, TokenCredentials $tokenCredentials)
|
97 | 141 | {
|
98 | 142 | return $data['name'];
|
99 | 143 | }
|
| 144 | + |
| 145 | + /** |
| 146 | + * @inheritDoc |
| 147 | + */ |
| 148 | + protected function additionalTemporaryCredentialsProtocolParameters() |
| 149 | + { |
| 150 | + return [ |
| 151 | + 'x_auth_access_type' => $this->getApplicationScope() |
| 152 | + ]; |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * Parse configuration array to set attributes. |
| 157 | + * |
| 158 | + * @param array $configuration |
| 159 | + * |
| 160 | + * @return void |
| 161 | + */ |
| 162 | + private function parseConfiguration(array $configuration = []) |
| 163 | + { |
| 164 | + $configToPropertyMap = [ |
| 165 | + 'scope' => 'applicationScope', |
| 166 | + ]; |
| 167 | + |
| 168 | + foreach ($configToPropertyMap as $config => $property) { |
| 169 | + if (isset($configuration[$config])) { |
| 170 | + $this->$property = $configuration[$config]; |
| 171 | + } |
| 172 | + } |
| 173 | + } |
100 | 174 | }
|
0 commit comments