Skip to content

Commit cf55f6d

Browse files
author
Eric Urban
authored
Merge pull request #101 from BingAds/v12-13-2
support AAD credentials etc
2 parents eb5533b + b1f12ad commit cf55f6d

File tree

215 files changed

+865
-812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+865
-812
lines changed

src/Auth/IOAuthService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ abstract class IOAuthService
1111
* Implementations of this abstract method must call the authorization server with the oauthRequestParameters passed in,
1212
* deserialize the response, and return back OAuth tokens.
1313
*/
14-
abstract function GetAccessTokens(OAuthRequestParameters $oauthParameters, $environment);
14+
abstract function GetAccessTokens(OAuthRequestParameters $oauthParameters, $environment, $requireLiveConnect);
1515
}

src/Auth/LiveComOAuthService.php

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/Auth/OAuthAuthorization.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ abstract class OAuthAuthorization extends Authentication
2727
*/
2828
public $Environment = ApiEnvironment::Production;
2929

30+
/**
31+
* Determines whether or not to require Live Connect instead of MS Identity in production.
32+
*/
33+
public $RequireLiveConnect = false;
34+
3035
public function __construct() {}
3136

3237
/**
@@ -81,6 +86,19 @@ public function withOAuthTokens($oauthTokens) {
8186
*/
8287
public function withEnvironment($environment) {
8388
$this->Environment = $environment;
89+
$this->RedirectUri=UriOAuthService::GetRedirectUrl($environment, $this->RequireLiveConnect);
90+
return $this;
91+
}
92+
93+
/**
94+
* Includes the require Live Connect flag.
95+
*
96+
* @param string $requireLiveConnect
97+
* @return OAuthAuthorization this builder
98+
*/
99+
public function withRequireLiveConnect($requireLiveConnect) {
100+
$this->RequireLiveConnect = $requireLiveConnect;
101+
$this->RedirectUri=UriOAuthService::GetRedirectUrl($this->Environment, $requireLiveConnect);
84102
return $this;
85103
}
86104

src/Auth/OAuthDesktopMobileImplicitGrant.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,6 @@ public function withState($state) {
3030
return $this;
3131
}
3232

33-
34-
/**
35-
* Includes the environment.
36-
*
37-
* @param string $environment
38-
* @return OAuthDesktopMobileImplicitGrant this builder
39-
*/
40-
public function withEnvironment($environment) {
41-
$this->Environment = $environment;
42-
$this->RedirectUri=LiveComOAuthService::GetRedirectUrl($environment);
43-
return $this;
44-
}
45-
4633
/**
4734
* Gets the Microsoft Account authorization endpoint where the user should be navigated to give their consent.
4835
*/
@@ -54,7 +41,7 @@ public function GetAuthorizationEndpoint(){
5441
->withRedirectUri($this->RedirectUri)
5542
->withState($this->State);
5643

57-
return LiveComOAuthService::GetAuthorizationEndpoint($oauthUrlParameters, $this->Environment);
44+
return UriOAuthService::GetAuthorizationEndpoint($oauthUrlParameters, $this->Environment, $this->RequireLiveConnect);
5845
}
5946

6047
/**

src/Auth/OAuthEndpointType.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 endpoint type to use for OAuth.
7+
*/
8+
final class OAuthEndpointType
9+
{
10+
/**
11+
* Production for MS Identity V2
12+
*/
13+
const ProductionMSIdentityV2 = 'ProductionMSIdentityV2';
14+
15+
/**
16+
* Production for Live Connect
17+
*/
18+
const ProductionLiveConnect = 'ProductionLiveConnect';
19+
20+
/**
21+
* Sandbox for Live Connect
22+
*/
23+
const SandboxLiveConnect = 'SandboxLiveConnect';
24+
}

src/Auth/OAuthWithAuthorizationCode.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class OAuthWithAuthorizationCode extends OAuthAuthorization {
2020
public function __construct() {
2121
parent::__construct();
2222

23-
$this->oauthService = new LiveComOAuthService(null);
23+
$this->oauthService = new UriOAuthService(null);
2424
}
2525

2626
/**
@@ -34,18 +34,6 @@ public function withClientSecret($clientSecret) {
3434
return $this;
3535
}
3636

37-
/**
38-
* Includes the environment.
39-
*
40-
* @param string $environment
41-
* @return OAuthWithAuthorizationCode this builder
42-
*/
43-
public function withEnvironment($environment) {
44-
$this->Environment = $environment;
45-
$this->RedirectUri=LiveComOAuthService::GetRedirectUrl($environment);
46-
return $this;
47-
}
48-
4937
/**
5038
* Includes the state.
5139
*
@@ -67,7 +55,7 @@ public function GetAuthorizationEndpoint(){
6755
$oauthUrlParameters->RedirectUri = $this->RedirectUri;
6856
$oauthUrlParameters->State = $this->State;
6957

70-
return LiveComOAuthService::GetAuthorizationEndpoint($oauthUrlParameters, $this->Environment);
58+
return UriOAuthService::GetAuthorizationEndpoint($oauthUrlParameters, $this->Environment, $this->RequireLiveConnect);
7159
}
7260

7361
/**
@@ -109,7 +97,7 @@ public function RequestOAuthTokensByResponseUri($responseUri)
10997
->withGrantParamName("code")
11098
->withGrantValue($code);
11199

112-
$this->OAuthTokens = $this->oauthService->GetAccessTokens($oauthRequestParameters, $this->Environment);
100+
$this->OAuthTokens = $this->oauthService->GetAccessTokens($oauthRequestParameters, $this->Environment, $this->RequireLiveConnect);
113101

114102
return $this->OAuthTokens;
115103
}
@@ -128,12 +116,11 @@ public function RequestOAuthTokensByRefreshToken($refreshToken)
128116
$oauthRequestParameters = (new OAuthRequestParameters())
129117
->withClientId($this->ClientId)
130118
->withClientSecret($this->ClientSecret)
131-
->withRedirectUri($this->RedirectUri)
132119
->withGrantType("refresh_token")
133120
->withGrantParamName("refresh_token")
134121
->withGrantValue($refreshToken);
135122

136-
$this->OAuthTokens = $this->oauthService->GetAccessTokens($oauthRequestParameters, $this->Environment);
123+
$this->OAuthTokens = $this->oauthService->GetAccessTokens($oauthRequestParameters, $this->Environment, $this->RequireLiveConnect);
137124

138125
return $this->OAuthTokens;
139126
}

0 commit comments

Comments
 (0)