11<?php
22/**
3- * A simple OAuth 2.0 handler.
4- *
5- * PHP version 5
6- *
73 * Copyright 2011, Google Inc. All Rights Reserved.
84 *
95 * Licensed under the Apache License, Version 2.0 (the "License");
2117 * @package GoogleApiAdsCommon
2218 * @subpackage Util
2319 * @category WebServices
24- * @copyright 2012 , Google Inc. All Rights Reserved.
20+ * @copyright 2011 , Google Inc. All Rights Reserved.
2521 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License,
2622 * Version 2.0
2723 */
2824require_once 'Google/Api/Ads/Common/Util/OAuth2Handler.php ' ;
2925require_once 'Google/Api/Ads/Common/Util/CurlUtils.php ' ;
3026
3127/**
32- * A simple OAuth 2.0 handler.
28+ * A simple OAuth2 handler.
29+ *
3330 * @package GoogleApiAdsCommon
3431 * @subpackage Util
3532 */
@@ -38,14 +35,13 @@ class SimpleOAuth2Handler extends OAuth2Handler {
3835 private $ curlUtils ;
3936
4037 /**
41- * Creates a new instance of this OAuth handler.
42- * @param string $server the auth server to make OAuth2 request against
43- * @param CurlUtils $curlUtils an instance of CurlUtils
38+ * @param array $scopes optional, Google API scopes this handler should use
39+ * @param CurlUtils $curlUtils optional, curl utility to be used for HTTP
4440 */
45- public function __construct ($ server = null , $ scope = null ,
46- $ curlUtils = null ) {
47- parent ::__construct ($ server , $ scope );
48- $ this ->curlUtils = is_null ( $ curlUtils) ? new CurlUtils () : $ curlUtils ;
41+ public function __construct (
42+ array $ scope = null , CurlUtils $ curlUtils = null ) {
43+ parent ::__construct ($ scope );
44+ $ this ->curlUtils = $ curlUtils === null ? new CurlUtils () : $ curlUtils ;
4945 }
5046
5147 /**
@@ -100,13 +96,16 @@ public function RefreshAccessToken(array $credentials) {
10096 /**
10197 * Makes an HTTP request to the given URL and extracts the returned OAuth2
10298 * response.
99+ *
103100 * @param string $url the URL to make the request to
104101 * @param array $params the parameters to include in the POST body
105102 * @return OAuthToken the returned token
106103 */
107104 protected function MakeRequest ($ url , $ params ) {
108105 $ ch = $ this ->curlUtils ->CreateSession ($ url );
109- $ this ->curlUtils ->SetOpt ($ ch , CURLOPT_POSTFIELDS , $ params );
106+ $ this ->curlUtils ->SetOpt ($ ch , CURLOPT_POST , 1 );
107+ $ this ->curlUtils ->SetOpt (
108+ $ ch , CURLOPT_POSTFIELDS , http_build_query ($ params ));
110109 $ response = $ this ->curlUtils ->Exec ($ ch );
111110 $ error = $ this ->curlUtils ->Error ($ ch );
112111 $ httpCode = $ this ->curlUtils ->GetInfo ($ ch , CURLINFO_HTTP_CODE );
0 commit comments