Skip to content

Commit 4ad815b

Browse files
authored
Merge pull request #153 from BingAds/jianyun/13.0.10
php sdk 13.0.10 release
2 parents d4fa828 + 0c06e82 commit 4ad815b

31 files changed

+566
-55
lines changed

samples/V13/AuthHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Microsoft\BingAds\Auth\AuthorizationData;
1414
use Microsoft\BingAds\Auth\OAuthTokenRequestException;
1515
use Microsoft\BingAds\Auth\ApiEnvironment;
16+
use Microsoft\BingAds\Auth\OAuthScope;
1617
use Microsoft\BingAds\Auth\ServiceClient;
1718
use Microsoft\BingAds\Auth\ServiceClientType;
1819

@@ -43,6 +44,7 @@ final class AuthHelper {
4344

4445
const DeveloperToken = 'BBD37VB98'; // For sandbox use BBD37VB98
4546
const ApiEnvironment = ApiEnvironment::Sandbox;
47+
const OAuthScope = OAuthScope::MSADS_MANAGE;
4648
const OAuthRefreshTokenPath = 'refresh.txt';
4749
const ClientId = 'db41b09d-6e50-4f4a-90ac-5a99caefb52f'; // For sandbox use db41b09d-6e50-4f4a-90ac-5a99caefb52f
4850

@@ -167,7 +169,8 @@ static function AuthenticateWithOAuth()
167169
{
168170
$authentication = (new OAuthDesktopMobileAuthCodeGrant())
169171
->withEnvironment(AuthHelper::ApiEnvironment)
170-
->withClientId(AuthHelper::ClientId);
172+
->withClientId(AuthHelper::ClientId)
173+
->withOAuthScope(AuthHelper::OAuthScope);
171174

172175
$GLOBALS['AuthorizationData'] = (new AuthorizationData())
173176
->withAuthentication($authentication)

src/Auth/IOAuthService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ abstract class IOAuthService
1313
*
1414
* @param OAuthRequestParameters $oauthRequestParameters
1515
* @param ApiEnvironment $environment
16-
* @param bool $requireLiveConnect
16+
* @param OAuthScope $oauthScope
1717
* @param string $tenant
1818
* @param array $additionalParams
1919
*/
20-
abstract function GetAccessTokens(OAuthRequestParameters $oauthRequestParameters, $environment, $requireLiveConnect, $tenant, $additionalParams);
20+
abstract function GetAccessTokens(OAuthRequestParameters $oauthRequestParameters, $environment, $oauthScope, $tenant, $additionalParams);
2121
}

src/Auth/OAuthAuthorization.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ abstract class OAuthAuthorization extends Authentication
3232
public $Environment = ApiEnvironment::Production;
3333

3434
/**
35-
* Determines whether or not to require Live Connect instead of MS Identity in production.
36-
* @var bool
35+
* Determines the scope used for OAuth authorization .
36+
* @var OAuthScope
3737
*/
38-
public $RequireLiveConnect = false;
38+
public $OAuthScope = OAuthScope::MSADS_MANAGE;
3939

4040
/**
4141
* Optional custom AAD tenant for MS Identity in production.
@@ -97,19 +97,19 @@ public function withOAuthTokens($oauthTokens) {
9797
*/
9898
public function withEnvironment($environment) {
9999
$this->Environment = $environment;
100-
$this->RedirectUri=UriOAuthService::GetRedirectUrl($environment, $this->RequireLiveConnect);
100+
$this->RedirectUri=UriOAuthService::GetRedirectUrl($environment, $this->OAuthScope);
101101
return $this;
102102
}
103103

104104
/**
105-
* Includes the require Live Connect flag.
105+
* Includes the OAuthScope.
106106
*
107-
* @param string $requireLiveConnect
107+
* @param OAuthScope $oauthScope
108108
* @return OAuthAuthorization this builder
109109
*/
110-
public function withRequireLiveConnect($requireLiveConnect) {
111-
$this->RequireLiveConnect = $requireLiveConnect;
112-
$this->RedirectUri=UriOAuthService::GetRedirectUrl($this->Environment, $requireLiveConnect);
110+
public function withOAuthScope($oauthScope) {
111+
$this->OAuthScope = $oauthScope;
112+
$this->RedirectUri=UriOAuthService::GetRedirectUrl($this->Environment, $oauthScope);
113113
return $this;
114114
}
115115

src/Auth/OAuthDesktopMobileImplicitGrant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function GetAuthorizationEndpoint(){
4646
return UriOAuthService::GetAuthorizationEndpoint(
4747
$oauthUrlParameters,
4848
$this->Environment,
49-
$this->RequireLiveConnect,
49+
$this->OAuthScope,
5050
$this->Tenant);
5151
}
5252

src/Auth/OAuthEndpointType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88
final class OAuthEndpointType
99
{
10+
/**
11+
* Production for MS Identity V2 with new MSADS scope
12+
*/
13+
const ProductionMSIdentityV2_MSScope = 'ProductionMSIdentityV2_MSScope';
14+
1015
/**
1116
* Production for MS Identity V2
1217
*/
@@ -20,5 +25,5 @@ final class OAuthEndpointType
2025
/**
2126
* Sandbox for Live Connect
2227
*/
23-
const SandboxLiveConnect = 'SandboxLiveConnect';
28+
const Sandbox = 'Sandbox';
2429
}

src/Auth/OAuthScope.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Microsoft\BingAds\Auth;
4+
5+
/**
6+
* Represents the scope to be used for OAuth authorization.
7+
*/
8+
final class OAuthScope
9+
{
10+
/**
11+
* Represents msads.manage OAuth scope
12+
*/
13+
const MSADS_MANAGE = 'msads.manage';
14+
15+
/**
16+
* Represents bingads.msnage OAuth scope
17+
*/
18+
const BINGADS_MANAGE = 'bingads.manage';
19+
20+
/**
21+
* Represents ads.manage OAuth scope
22+
*/
23+
const ADS_MANAGE = 'ads.manage';
24+
}

src/Auth/OAuthWithAuthorizationCode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function GetAuthorizationEndpoint(){
6262
return UriOAuthService::GetAuthorizationEndpoint(
6363
$oauthUrlParameters,
6464
$this->Environment,
65-
$this->RequireLiveConnect,
65+
$this->OAuthScope,
6666
$this->Tenant);
6767
}
6868

@@ -115,7 +115,7 @@ public function RequestOAuthTokensByResponseUri($responseUri, $additionalParams=
115115
$this->OAuthTokens = $this->oauthService->GetAccessTokens(
116116
$oauthRequestParameters,
117117
$this->Environment,
118-
$this->RequireLiveConnect,
118+
$this->OAuthScope,
119119
$this->Tenant,
120120
$additionalParams
121121
);
@@ -150,7 +150,7 @@ public function RequestOAuthTokensByRefreshToken($refreshToken, $additionalParam
150150
$this->OAuthTokens = $this->oauthService->GetAccessTokens(
151151
$oauthRequestParameters,
152152
$this->Environment,
153-
$this->RequireLiveConnect,
153+
$this->OAuthScope,
154154
$this->Tenant,
155155
$additionalParams
156156
);

src/Auth/ServiceClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private function RefreshServiceProxy()
242242
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
243243
// Disable keep_alive to avoid 'Process open FD table is full'
244244
'keep_alive' => FALSE,
245-
'user_agent' => 'BingAdsSDKPHP ' . '13.0.9 ' . PHP_VERSION,
245+
'user_agent' => 'BingAdsSDKPHP ' . '13.0.10 ' . PHP_VERSION,
246246
'cache_wsdl' => 'WSDL_CACHE_NONE',
247247

248248
/**

src/Auth/UriOAuthService.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
class UriOAuthService extends IOAuthService
99
{
1010
const ENDPOINT_URLS = array(
11+
'ProductionMSIdentityV2_MSScope' => array(
12+
'RedirectUrl' => 'https://login.microsoftonline.com/common/oauth2/nativeclient',
13+
'OAuthTokenUrl' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
14+
'AuthorizationEndpointUrl' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?scope=https://ads.microsoft.com%2Fmsads.manage+offline_access',
15+
'Scope' => 'https://ads.microsoft.com/msads.manage offline_access'
16+
),
1117
'ProductionMSIdentityV2' => array(
1218
'RedirectUrl' => 'https://login.microsoftonline.com/common/oauth2/nativeclient',
1319
'OAuthTokenUrl' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
@@ -20,11 +26,11 @@ class UriOAuthService extends IOAuthService
2026
'AuthorizationEndpointUrl' => 'https://login.live.com/oauth20_authorize.srf?scope=bingads.manage',
2127
'Scope' => 'bingads.manage'
2228
),
23-
'SandboxLiveConnect' => array(
24-
'RedirectUrl' => 'https://login.live-int.com/oauth20_desktop.srf',
25-
'OAuthTokenUrl' => 'https://login.live-int.com/oauth20_token.srf',
26-
'AuthorizationEndpointUrl' => 'https://login.live-int.com/oauth20_authorize.srf?scope=bingads.manage&prompt=login',
27-
'Scope' => 'bingads.manage'
29+
'Sandbox' => array(
30+
'RedirectUrl' => 'https://login.windows-ppe.net/common/oauth2/nativeclient',
31+
'OAuthTokenUrl' => 'https://login.windows-ppe.net/consumers/oauth2/v2.0/token',
32+
'AuthorizationEndpointUrl' => 'https://login.windows-ppe.net/consumers/oauth2/v2.0/authorize?scope=https://api.ads.microsoft.com/msads.manage+offline_access&prompt=login',
33+
'Scope' => 'https://api.ads.microsoft.com/msads.manage offline_access'
2834
),
2935
);
3036

@@ -45,16 +51,16 @@ public function __construct($httpService) {
4551
*
4652
* @param OAuthRequestParameters $oauthRequestParameters
4753
* @param ApiEnvironment $environment
48-
* @param bool $requireLiveConnect
54+
* @param OAuthScope $oauthScope
4955
* @param string $tenant
5056
* @param array $additionalParams
5157
*
5258
* @return OAuthTokens
5359
* @throws Exception
5460
*/
55-
public function GetAccessTokens(OAuthRequestParameters $oauthRequestParameters, $environment, $requireLiveConnect, $tenant, $additionalParams)
61+
public function GetAccessTokens(OAuthRequestParameters $oauthRequestParameters, $environment, $oauthScope, $tenant, $additionalParams)
5662
{
57-
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $requireLiveConnect);
63+
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $oauthScope);
5864

5965
$accessTokenExchangeParams = array(
6066
'client_id' => $oauthRequestParameters->ClientId,
@@ -136,13 +142,13 @@ public function GetAccessTokens(OAuthRequestParameters $oauthRequestParameters,
136142
*
137143
* @param OAuthUrlParameters $parameters
138144
* @param ApiEnvironment $environment
139-
* @param bool $requireLiveConnect
145+
* @param OAuthScope $oauthScope
140146
*
141147
* @return string
142148
*/
143-
public static function GetAuthorizationEndpoint(OAuthUrlParameters $parameters, $environment, $requireLiveConnect, $tenant)
149+
public static function GetAuthorizationEndpoint(OAuthUrlParameters $parameters, $environment, $oauthScope, $tenant)
144150
{
145-
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $requireLiveConnect);
151+
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $oauthScope);
146152

147153
$authorizationEndpointUrl = UriOAuthService::ENDPOINT_URLS[$endpointType]['AuthorizationEndpointUrl'];
148154

@@ -160,27 +166,39 @@ public static function GetAuthorizationEndpoint(OAuthUrlParameters $parameters,
160166
) . (($parameters->State == null) ? "" : ("&state=" . $parameters->State));
161167
}
162168

163-
private static function GetOAuthEndpointType($environment, $requireLiveConnect)
169+
private static function GetOAuthEndpointType($environment, $oauthScope)
164170
{
165171
$endpointType;
166172
if ($environment == ApiEnvironment::Production)
167173
{
168-
$endpointType = $requireLiveConnect ? OAuthEndpointType::ProductionLiveConnect : OAuthEndpointType::ProductionMSIdentityV2;
174+
switch ($oauthScope) {
175+
case OAuthScope::MSADS_MANAGE:
176+
$endpointType = OAuthEndpointType::ProductionMSIdentityV2_MSScope;
177+
break;
178+
case OAuthScope::BINGADS_MANAGE:
179+
$endpointType = OAuthEndpointType::ProductionLiveConnect;
180+
break;
181+
case OAuthScope::ADS_MANAGE:
182+
$endpointType = OAuthEndpointType::ProductionMSIdentityV2;
183+
break;
184+
default:
185+
$endpointType = OAuthEndpointType::ProductionMSIdentityV2_MSScope;
186+
}
169187
}
170188
else
171189
{
172-
$endpointType = OAuthEndpointType::SandboxLiveConnect;
190+
$endpointType = OAuthEndpointType::Sandbox;
173191
}
174192
return $endpointType;
175193
}
176194

177-
public static function GetRedirectUrl($environment, $requireLiveConnect) {
178-
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $requireLiveConnect);
195+
public static function GetRedirectUrl($environment, $oauthScope) {
196+
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $oauthScope);
179197
return UriOAuthService::ENDPOINT_URLS[$endpointType]['RedirectUrl'];
180198
}
181199

182-
public static function GetAuthTokenUrl($environment, $requireLiveConnect, $tenant) {
183-
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $requireLiveConnect);
200+
public static function GetAuthTokenUrl($environment, $oauthScope, $tenant) {
201+
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $oauthScope);
184202

185203
$OAuthTokenUrl = UriOAuthService::ENDPOINT_URLS[$endpointType]['OAuthTokenUrl'];
186204

@@ -192,8 +210,8 @@ public static function GetAuthTokenUrl($environment, $requireLiveConnect, $tenan
192210
return $OAuthTokenUrl;
193211
}
194212

195-
public static function GetAuthorizeUrl($environment, $requireLiveConnect, $tenant) {
196-
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $requireLiveConnect);
213+
public static function GetAuthorizeUrl($environment, $oauthScope, $tenant) {
214+
$endpointType = UriOAuthService::GetOAuthEndpointType($environment, $oauthScope);
197215

198216
$authorizationEndpointUrl = UriOAuthService::ENDPOINT_URLS[$endpointType]['AuthorizationEndpointUrl'];
199217

src/V13/Bulk/DownloadEntity.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ final class DownloadEntity
419419

420420
/** Reserved. */
421421
const AdGroupVideoAdExtensions = 'AdGroupVideoAdExtensions';
422+
423+
/** Reserved. */
424+
const Videos = 'Videos';
422425
}
423426

424427
}

0 commit comments

Comments
 (0)