1 | <?php |
||
6 | class Credential implements \ArrayAccess |
||
7 | { |
||
8 | protected $consumer_key; |
||
9 | protected $consumer_secret; |
||
10 | protected $token = ''; |
||
11 | protected $token_secret = ''; |
||
12 | |||
13 | 53 | public function __construct(array $params = []) |
|
22 | |||
23 | public function with(array $params = []) |
||
31 | |||
32 | 9 | public function toArray($assoc = false) |
|
33 | 9 | { |
|
34 | 9 | $values = get_object_vars($this); |
|
35 | 9 | return $assoc ? $values : array_values($values); |
|
36 | } |
||
37 | |||
38 | 6 | public function offsetGet($offset) |
|
39 | 6 | { |
|
40 | 6 | return $this->{CredentialNormalizer::normalizeCredentialParamName($offset)}; |
|
41 | } |
||
42 | |||
43 | public function offsetSet($offset, $value) |
||
47 | |||
48 | public function offsetUnset($offset) |
||
52 | |||
53 | public function offsetExists($offset) |
||
57 | |||
58 | public function __get($key) |
||
62 | |||
63 | public function __isset($key) |
||
67 | |||
68 | public function getAuthorizeUrl($force_login = false) |
||
76 | |||
77 | public function getAuthenticateUrl($force_login = false) |
||
85 | |||
86 | 40 | public function getOAuthHeaders($url, $method, array $endpoint_params) |
|
99 | |||
100 | public function getBasicHeaders() |
||
108 | |||
109 | public function getBearerHeaders() |
||
113 | |||
114 | 6 | public function getOAuthHeadersForOAuthEcho() |
|
115 | 6 | { |
|
116 | 6 | $url = 'https://api.twitter.com/1.1/account/verify_credentials.json'; |
|
117 | 6 | $headers = static::getOAuthHeaders($url, 'GET', []); |
|
118 | return [ |
||
119 | 6 | 'X-Auth-Service-Provider: ' . $url, |
|
120 | 6 | 'X-Verify-Credentials-Authorization: OAuth realm="http://api.twitter.com/", ' . substr($headers[0], 21), |
|
121 | ]; |
||
122 | } |
||
123 | |||
124 | 2 | public function getOAuthHeadersForRequestToken($oauth_callback = null) |
|
125 | 2 | { |
|
126 | 2 | return static::buildOAuthHeaders( |
|
127 | 2 | 'https://api.twitter.com/oauth/request_token', |
|
128 | 2 | 'POST', |
|
129 | [ |
||
130 | 2 | 'oauth_consumer_key' => $this->consumer_key, |
|
131 | 2 | ] + ($oauth_callback === null ? [] : |
|
132 | [ |
||
133 | 2 | 'oauth_callback' => $oauth_callback, |
|
134 | ]), |
||
135 | 2 | [$this->consumer_secret, ''], |
|
136 | 2 | [] |
|
137 | ); |
||
138 | } |
||
139 | |||
140 | 2 | public function getOAuthHeadersForAccessToken($oauth_verifier) |
|
141 | 2 | { |
|
142 | 2 | return static::buildOAuthHeaders( |
|
143 | 2 | 'https://api.twitter.com/oauth/access_token', |
|
144 | 2 | 'POST', |
|
145 | [ |
||
146 | 2 | 'oauth_consumer_key' => $this->consumer_key, |
|
147 | 2 | 'oauth_token' => $this->token, |
|
148 | 2 | 'oauth_verifier' => $oauth_verifier, |
|
149 | ], |
||
150 | 2 | [$this->consumer_secret, $this->token_secret], |
|
151 | 2 | [] |
|
152 | ); |
||
153 | } |
||
154 | |||
155 | 2 | public function getXAuthHeadersForAccessToken($username, $password) |
|
156 | 2 | { |
|
157 | 2 | return static::buildOAuthHeaders( |
|
158 | 2 | 'https://api.twitter.com/oauth/access_token', |
|
159 | 2 | 'POST', |
|
160 | [ |
||
161 | 2 | 'oauth_consumer_key' => $this->consumer_key, |
|
162 | ], |
||
163 | 2 | [$this->consumer_secret, ''], |
|
164 | [ |
||
165 | 2 | 'x_auth_username' => $username, |
|
166 | 2 | 'x_auth_password' => $password, |
|
167 | 2 | 'x_auth_mode' => 'client_auth', |
|
168 | ] |
||
169 | ); |
||
170 | } |
||
171 | |||
172 | 46 | protected static function buildOAuthHeaders($url, $method, array $oauth_params, array $key_params, array $endpoint_params) |
|
198 | } |
||
199 |