Vyacheslav Slinko

Check default parameters in authorize url

Showing 1 changed file with 12 additions and 10 deletions
@@ -132,7 +132,9 @@ class OAuth2_Service @@ -132,7 +132,9 @@ class OAuth2_Service
132 if ($this->_scope) { 132 if ($this->_scope) {
133 $parameters['scope'] = $this->_scope; 133 $parameters['scope'] = $this->_scope;
134 } 134 }
135 - $url = $this->_configuration->getAuthorizeEndpoint() . '?' . http_build_query($parameters); 135 +
  136 + $url = $this->_configuration->getAuthorizeEndpoint();
  137 + $url .= (strpos($url, '?') !== false ? '&' : '?') . http_build_query($parameters);
136 138
137 header('Location: ' . $url); 139 header('Location: ' . $url);
138 die(); 140 die();
@@ -163,7 +165,7 @@ class OAuth2_Service @@ -163,7 +165,7 @@ class OAuth2_Service
163 if ($this->_scope) { 165 if ($this->_scope) {
164 $parameters['scope'] = $this->_scope; 166 $parameters['scope'] = $this->_scope;
165 } 167 }
166 - 168 +
167 $http = new OAuth2_HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters)); 169 $http = new OAuth2_HttpClient($this->_configuration->getAccessTokenEndpoint(), 'POST', http_build_query($parameters));
168 //$http->setDebug(true); 170 //$http->setDebug(true);
169 $http->execute(); 171 $http->execute();
@@ -227,7 +229,7 @@ class OAuth2_Service @@ -227,7 +229,7 @@ class OAuth2_Service
227 throw new OAuth2_Exception('no access_token found'); 229 throw new OAuth2_Exception('no access_token found');
228 } 230 }
229 231
230 - $token = new OAuth2_Token($response['access_token'], 232 + $token = new OAuth2_Token($response['access_token'],
231 isset($response['refresh_token']) ? $response['refresh_token'] : $oldRefreshToken, 233 isset($response['refresh_token']) ? $response['refresh_token'] : $oldRefreshToken,
232 isset($response['expires_in']) ? $response['expires_in'] : null); 234 isset($response['expires_in']) ? $response['expires_in'] : null);
233 235
@@ -239,7 +241,7 @@ class OAuth2_Service @@ -239,7 +241,7 @@ class OAuth2_Service
239 foreach ($response as $key => $value) { 241 foreach ($response as $key => $value) {
240 $token->{'set' . $key}($value); 242 $token->{'set' . $key}($value);
241 } 243 }
242 - 244 +
243 $this->_dataStore->storeAccessToken($token); 245 $this->_dataStore->storeAccessToken($token);
244 246
245 return $token; 247 return $token;
@@ -265,12 +267,12 @@ class OAuth2_Service @@ -265,12 +267,12 @@ class OAuth2_Service
265 267
266 $parameters = null; 268 $parameters = null;
267 269
268 - if (!$this->_configuration->getUseOnlyAuthorizationHeader()){ 270 + if (!$this->_configuration->getUseOnlyAuthorizationHeader()){
269 /* 271 /*
270 http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1 272 http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-5.1
271 Clients SHOULD only use the request URI or body when the 273 Clients SHOULD only use the request URI or body when the
272 "Authorization" request header field is not available, and MUST NOT 274 "Authorization" request header field is not available, and MUST NOT
273 - use more than one method in each request.only one method should be used as per the Draft. 275 + use more than one method in each request.only one method should be used as per the Draft.
274 Allow to override correct behavior for misimplemented servers 276 Allow to override correct behavior for misimplemented servers
275 */ 277 */
276 if ($method !== 'GET') { 278 if ($method !== 'GET') {
@@ -291,7 +293,7 @@ class OAuth2_Service @@ -291,7 +293,7 @@ class OAuth2_Service
291 $parameters = $postBody; 293 $parameters = $postBody;
292 } 294 }
293 } 295 }
294 - 296 +
295 if (! empty($uriParameters)) { 297 if (! empty($uriParameters)) {
296 $endpoint .= (strpos($endpoint, '?') !== false ? '&' : '?') . http_build_query($uriParameters); 298 $endpoint .= (strpos($endpoint, '?') !== false ? '&' : '?') . http_build_query($uriParameters);
297 } 299 }
@@ -610,7 +612,7 @@ class OAuth2_HttpClient @@ -610,7 +612,7 @@ class OAuth2_HttpClient
610 print_r($this->_response); 612 print_r($this->_response);
611 echo "</pre>"; 613 echo "</pre>";
612 } 614 }
613 - 615 +
614 curl_close($ch); 616 curl_close($ch);
615 } 617 }
616 618
@@ -629,11 +631,11 @@ class OAuth2_HttpClient @@ -629,11 +631,11 @@ class OAuth2_HttpClient
629 } 631 }
630 632
631 /** 633 /**
632 - * @param boolean $debug 634 + * @param boolean $debug
633 */ 635 */
634 public function setDebug($debug) { 636 public function setDebug($debug) {
635 $this->_debug = $debug; 637 $this->_debug = $debug;
636 } 638 }
637 } 639 }
638 640
639 -class OAuth2_Exception extends Exception {} 641 +class OAuth2_Exception extends Exception {}