88class 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
0 commit comments