Skip to content

Commit 8a1b83f

Browse files
committed
Preparing src for release 13.0.0
1 parent 4ad1acf commit 8a1b83f

File tree

11 files changed

+38
-121
lines changed

11 files changed

+38
-121
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 13.0.0
2+
3+
Common:
4+
- Fixed
5+
[issue #162](https://github.com/googleads/googleads-php-lib/issues/162).
6+
- Removed the ability to set the OAuth2 server host as it is not useful.
7+
18
### 12.0.0
29

310
AdWords:

src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public function ValidateUser() {
388388
*/
389389
public function GetDefaultOAuth2Handler($className = null) {
390390
$className = !empty($className) ? $className : self::OAUTH2_HANDLER_CLASS;
391-
return new $className($this->GetAuthServer(), $this->GetScopes());
391+
return new $className($this->GetScopes());
392392
}
393393

394394
/**
@@ -407,4 +407,3 @@ public function __call($name, $arguments) {
407407
}
408408
}
409409
}
410-

src/Google/Api/Ads/Common/Lib/AdsUser.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ abstract class AdsUser {
5050
private $wsdlCache;
5151
private $forceHttpVersion;
5252
private $forceAddXsiTypes;
53-
private $authServer;
5453
private $oauth2Info;
5554
private $oauth2Handler;
5655
private $isIncludeUtilitiesInUserAgent;
@@ -260,9 +259,6 @@ public function LoadSettings($settingsIniPath, $defaultVersion,
260259
$this->Define('HTTP_PROXY_PASSWORD', $proxyPassword);
261260
}
262261

263-
// Auth settings.
264-
$this->authServer = $this->GetSetting($settingsIni, 'AUTH', 'AUTH_SERVER',
265-
'https://accounts.google.com');
266262
// OAuth2.
267263
$this->oauth2Handler = $this->GetDefaultOAuth2Handler(
268264
$this->GetSetting($settingsIni, 'AUTH', 'OAUTH2_HANDLER_CLASS'));
@@ -398,14 +394,6 @@ public function GetForceAddXsiTypes() {
398394
return $this->forceAddXsiTypes;
399395
}
400396

401-
/**
402-
* Gets the server used for authentication.
403-
* @return string the server used for authentiation
404-
*/
405-
public function GetAuthServer() {
406-
return $this->authServer;
407-
}
408-
409397
/**
410398
* Gets the OAuth2 info for this user.
411399
* @return array the OAuth2 info for this user
@@ -556,4 +544,3 @@ protected function ValidateOAuth2Info() {
556544
}
557545
}
558546
}
559-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
LIB_VERSION = 12.0.0
1+
LIB_VERSION = 13.0.0
22
LIB_NAME = "Common-PHP"

src/Google/Api/Ads/Common/Util/OAuth2Handler.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php
22
/**
3-
* An abstract class for Google OAuth 2.0 flow.
4-
*
5-
* PHP version 5
6-
*
7-
* Copyright 2011, Google Inc. All Rights Reserved.
3+
* Copyright 2012, Google Inc. All Rights Reserved.
84
*
95
* Licensed under the Apache License, Version 2.0 (the "License");
106
* you may not use this file except in compliance with the License.
@@ -29,6 +25,7 @@
2925

3026
/**
3127
* An abstract class for Google OAuth2 flow.
28+
*
3229
* @package GoogleApiAdsCommon
3330
* @subpackage Util
3431
*/
@@ -39,24 +36,16 @@ abstract class OAuth2Handler {
3936
*/
4037
const REFRESH_BUFFER = 60;
4138
const DEFAULT_REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
42-
const AUTHORIZE_ENDPOINT = 'https://accounts.google.com/o/oauth2/auth';
43-
const ACCESS_ENDPOINT = 'https://accounts.google.com/o/oauth2/token';
39+
const AUTHORIZE_ENDPOINT = 'https://accounts.google.com/o/oauth2/v2/auth';
40+
const ACCESS_ENDPOINT = 'https://www.googleapis.com/oauth2/v4/token';
4441

45-
private $server;
4642
private $scopes;
4743

4844
/**
49-
* Constructor.
50-
*
51-
* @param string $server the auth server to make OAuth2 request against
45+
* @param array $scopes optional, Google API scopes this handler should use
5246
*/
53-
public function __construct($server = null, $scopes = null) {
54-
$this->server = $server;
55-
if ($scopes === null) {
56-
$this->scopes = array();
57-
} else {
58-
$this->scopes = $scopes;
59-
}
47+
public function __construct(array $scopes = null) {
48+
$this->scopes = $scopes === null ? array() : $scopes;
6049
}
6150

6251
/**
@@ -264,11 +253,7 @@ protected function GetAccessEndpoint($params = null) {
264253
* @return string the endpoint
265254
*/
266255
private function GetEndpoint($endpoint, $params = null) {
267-
$endpoint = UrlUtils::AddParamsToUrl($endpoint, $params);
268-
if (!empty($this->server)) {
269-
$endpoint = UrlUtils::ReplaceServerInUrl($endpoint, $this->server);
270-
}
271-
return $endpoint;
256+
return UrlUtils::AddParamsToUrl($endpoint, $params);
272257
}
273258

274259
/**
@@ -299,4 +284,3 @@ public function __construct($message, $code = null) {
299284
parent::__construct($message, $code);
300285
}
301286
}
302-

src/Google/Api/Ads/Common/Util/SimpleOAuth2Handler.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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");
@@ -21,15 +17,16 @@
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
*/
2824
require_once 'Google/Api/Ads/Common/Util/OAuth2Handler.php';
2925
require_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);

src/Google/Api/Ads/Dfp/Lib/DfpUser.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function SetScopes($scopes) {
244244
*/
245245
public function GetDefaultOAuth2Handler($className = null) {
246246
$className = !empty($className) ? $className : self::OAUTH2_HANDLER_CLASS;
247-
return new $className($this->GetAuthServer(), $this->GetScopes());
247+
return new $className($this->GetScopes());
248248
}
249249

250250

@@ -287,4 +287,3 @@ public function __call($name, $arguments) {
287287
}
288288
}
289289
}
290-

src/Google/Api/Ads/Dfp/settings.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ WSDL_CACHE = 0
4848
; PASSWORD = "<PASSWORD>"
4949

5050
[AUTH]
51-
; The server to use when making OAuth2 requests.
52-
; This normally doesn't need to be changed from the default value
53-
; "https://accounts.google.com".
54-
; AUTH_SERVER = "<SERVER>"
55-
5651
; The OAuth2Handler class to use for OAuth2 flow.
5752
; OAUTH2_HANDLER_CLASS = "SimpleOAuth2Handler"
5853

@@ -71,4 +66,3 @@ VERIFY_HOST = 0
7166

7267
; The certificate authority file to use when performing peer validation.
7368
; CA_FILE = "<PATH TO CERTIFICATE AUTHORITY FILE>"
74-

tests/Google/Api/Ads/Common/Lib/AdsUserTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,9 @@ public function testLoadSettings_Proxy() {
308308
* @covers AdsUser::LoadSettings
309309
*/
310310
public function testLoadSettings_Auth() {
311-
$server = 'http://localhost';
312311
$oAuth2HandlerClass = 'SimpleOAuth2Handler';
313312
$settings = array(
314313
'AUTH' => array(
315-
'AUTH_SERVER' => $server,
316314
'OAUTH2_HANDLER_CLASS' => $oAuth2HandlerClass,
317315
),
318316
);
@@ -321,7 +319,6 @@ public function testLoadSettings_Auth() {
321319
$user->LoadSettings($settingsFilePath, self::DEFAULT_VERSION,
322320
self::DEFAULT_SERVER, self::DEFAULT_LOGS_DIR,
323321
$this->logsRelativePathBase);
324-
$this->assertEquals($server, $user->GetAuthServer());
325322
$this->assertEquals($oAuth2HandlerClass,
326323
get_class($user->GetOAuth2Handler()));
327324
}
@@ -339,7 +336,6 @@ public function testLoadSettings_Auth_Defaults() {
339336
$user->LoadSettings($settingsFilePath, self::DEFAULT_VERSION,
340337
self::DEFAULT_SERVER, self::DEFAULT_LOGS_DIR,
341338
$this->logsRelativePathBase);
342-
$this->assertEquals('https://accounts.google.com', $user->GetAuthServer());
343339
$this->assertEquals('SimpleOAuth2Handler',
344340
get_class($user->GetOAuth2Handler()));
345341
}
@@ -433,8 +429,7 @@ public function GetClientLibraryNameAndVersion() {
433429

434430
public function GetDefaultOAuth2Handler($className = null) {
435431
$className = !empty($className) ? $className : self::HANDLER_CLASS;
436-
return new $className($this->GetAuthServer(), self::OAUTH2_SCOPE);
432+
return new $className(array(self::OAUTH2_SCOPE));
437433
}
438434

439435
}
440-

tests/Google/Api/Ads/Common/Util/OAuth2HandlerTest.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function setup() {
3838
date_default_timezone_set('America/New_York');
3939
$this->scopes = array('TEST_SCOPE');
4040

41-
$this->oauth2Handler = new TestOAuth2Handler(null, $this->scopes);
41+
$this->oauth2Handler = new TestOAuth2Handler($this->scopes);
4242
}
4343

4444
public function testMultipleScopes() {
4545
$scopes = array('TEST_SCOPE1', 'TEST_SCOPE2', 'TEST_SCOPE3');
46-
$this->oauth2Handler = new TestOAuth2Handler(null, $scopes);
46+
$this->oauth2Handler = new TestOAuth2Handler($scopes);
4747

4848
$credentials = array('client_id' => 'TEST_CLIENT_ID');
4949

@@ -68,7 +68,6 @@ public function testMultipleScopes() {
6868
public function testGetAuthorizationUrl() {
6969
$credentials = array('client_id' => 'TEST_CLIENT_ID');
7070

71-
7271
$url = $this->oauth2Handler->GetAuthorizationUrl($credentials);
7372

7473
$urlParts = parse_url($url);
@@ -77,7 +76,7 @@ public function testGetAuthorizationUrl() {
7776
$this->assertFalse(isset($urlParts['port']));
7877
$this->assertFalse(isset($urlParts['user']));
7978
$this->assertFalse(isset($urlParts['pass']));
80-
$this->assertEquals('/o/oauth2/auth', $urlParts['path']);
79+
$this->assertEquals('/o/oauth2/v2/auth', $urlParts['path']);
8180
$this->assertFalse(isset($urlParts['fragment']));
8281

8382
$params = array();
@@ -89,22 +88,6 @@ public function testGetAuthorizationUrl() {
8988
$this->assertEquals('online', $params['access_type']);
9089
}
9190

92-
public function testGetAuthorizationUrl_AlternateServer() {
93-
$scheme = 'http';
94-
$authServer = 'www.foo.com';
95-
$scopes = array('TEST_SCOPE');
96-
$this->oauth2Handler = new TestOAuth2Handler(
97-
sprintf('%s://%s', $scheme, $authServer), $scopes);
98-
$credentials = array('client_id' => 'TEST_CLIENT_ID');
99-
100-
101-
$url = $this->oauth2Handler->GetAuthorizationUrl($credentials);
102-
103-
$urlParts = parse_url($url);
104-
$this->assertEquals($scheme, $urlParts['scheme']);
105-
$this->assertEquals($authServer, $urlParts['host']);
106-
}
107-
10891
/**
10992
* @expectedException OAuth2Exception
11093
*/

0 commit comments

Comments
 (0)