diff --git a/examples/AdWords/CSharp/App.config b/examples/AdWords/CSharp/App.config index 1ee298baf62..a566c03c3c7 100644 --- a/examples/AdWords/CSharp/App.config +++ b/examples/AdWords/CSharp/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/examples/AdWords/CSharp/OAuth/ConsoleExample.cs b/examples/AdWords/CSharp/OAuth/ConsoleExample.cs index 4c6f7541c1c..bca23f4a7c5 100644 --- a/examples/AdWords/CSharp/OAuth/ConsoleExample.cs +++ b/examples/AdWords/CSharp/OAuth/ConsoleExample.cs @@ -48,7 +48,7 @@ namespace Google.Api.Ads.AdWords.Examples.CSharp.OAuth { /// /// 3. Replace the Main() method with this class's method. /// 4. Copy App.config from AdWords.Examples.CSharp project, and configure - /// it as shown in ths project's Web.config. + /// it as shown in ths project's App.config. /// 5. Compile and run this example. /// public class ConsoleExample { @@ -58,14 +58,17 @@ public class ConsoleExample { /// Command line arguments. static void Main(string[] args) { AdWordsUser user = new AdWordsUser(); - AdWordsAppConfig config = (user.Config as AdWordsAppConfig); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + + // This code example shows how to run an AdWords API web application + // while incorporating the OAuth2 installed application flow into your + // application. If your application uses a single MCC login to make calls + // to all your accounts, you shouldn't use this code example. Instead, you + // should run OAuthTokenGenerator.exe to generate a refresh + // token and use that configuration in your application's App.config. + AdWordsAppConfig config = user.Config as AdWordsAppConfig; + if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - DoAuth2Authorization(user); - } - } else { - throw new Exception("Authorization mode is not OAuth."); + DoAuth2Authorization(user); } Console.Write("Enter the customer id: "); diff --git a/examples/AdWords/CSharp/OAuth/Default.aspx.cs b/examples/AdWords/CSharp/OAuth/Default.aspx.cs index a110c7b78ae..65d2c212175 100644 --- a/examples/AdWords/CSharp/OAuth/Default.aspx.cs +++ b/examples/AdWords/CSharp/OAuth/Default.aspx.cs @@ -55,17 +55,12 @@ protected void OnAuthorizeButtonClick(object sender, EventArgs e) { // while incorporating the OAuth2 web application flow into your // application. If your application uses a single MCC login to make calls // to all your accounts, you shouldn't use this code example. Instead, you - // should run Common\Util\OAuth2TokenGenerator.cs to generate a refresh - // token and set that in user.Config.OAuth2RefreshToken field, or set - // OAuth2RefreshToken key in your App.config / Web.config. + // should run OAuthTokenGenerator.exe to generate a refresh + // token and use that configuration in your website's Web.config. AdWordsAppConfig config = user.Config as AdWordsAppConfig; - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - Response.Redirect("OAuthLogin.aspx"); - } - } else { - throw new Exception("Authorization mode is not OAuth."); + if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { + Response.Redirect("OAuthLogin.aspx"); } } @@ -192,14 +187,9 @@ protected void OnGetCampaignsButtonClick(object sender, EventArgs e) { /// private void ConfigureUserForOAuth() { AdWordsAppConfig config = (user.Config as AdWordsAppConfig); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { + if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { user.OAuthProvider = (OAuth2ProviderForApplications) Session["OAuthProvider"]; - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - user.OAuthProvider = (OAuth2ProviderForApplications) Session["OAuthProvider"]; - } - } else { - throw new Exception("Authorization mode is not OAuth."); } } diff --git a/examples/AdWords/CSharp/OAuth/OAuthLogin.aspx.cs b/examples/AdWords/CSharp/OAuth/OAuthLogin.aspx.cs index 86ed1938f65..d7a9ad3b164 100644 --- a/examples/AdWords/CSharp/OAuth/OAuthLogin.aspx.cs +++ b/examples/AdWords/CSharp/OAuth/OAuthLogin.aspx.cs @@ -43,11 +43,9 @@ protected void Page_Load(object sender, EventArgs e) { // Create an AdWordsAppConfig object with the default settings in // App.config. AdWordsAppConfig config = new AdWordsAppConfig(); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - DoAuth2Configuration(config); - } + if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { + DoAuth2Configuration(config); } } diff --git a/examples/AdWords/CSharp/OAuth/Properties/Properties.cs b/examples/AdWords/CSharp/OAuth/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/examples/AdWords/CSharp/OAuth/Properties/Properties.cs +++ b/examples/AdWords/CSharp/OAuth/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/examples/AdWords/CSharp/OAuth/Web.config b/examples/AdWords/CSharp/OAuth/Web.config index c140a7e5e84..e3afa35ff57 100644 --- a/examples/AdWords/CSharp/OAuth/Web.config +++ b/examples/AdWords/CSharp/OAuth/Web.config @@ -57,7 +57,6 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - - - - - - - diff --git a/examples/AdWords/CSharp/Properties/Properties.cs b/examples/AdWords/CSharp/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/examples/AdWords/CSharp/Properties/Properties.cs +++ b/examples/AdWords/CSharp/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/examples/AdWords/CSharp/v201402/AccountManagement/GetAccountAlerts.cs b/examples/AdWords/CSharp/v201402/AccountManagement/GetAccountAlerts.cs index c529ae4edab..2eb5a7b17d2 100644 --- a/examples/AdWords/CSharp/v201402/AccountManagement/GetAccountAlerts.cs +++ b/examples/AdWords/CSharp/v201402/AccountManagement/GetAccountAlerts.cs @@ -24,8 +24,8 @@ namespace Google.Api.Ads.AdWords.Examples.CSharp.v201402 { /// /// This code example gets all alerts for all clients of an MCC account. - /// The effective user (ClientCustomerId or AuthToken) must be an MCC user - /// to get results. This code example won't work with Test Accounts. See + /// The effective user (ClientCustomerId or OAuth2 header) must be an MCC + /// user to get results. This code example won't work with Test Accounts. See /// https://developers.google.com/adwords/api/docs/test-accounts /// /// Tags: AlertService.get @@ -52,8 +52,8 @@ public static void Main(string[] args) { public override string Description { get { return "This code example gets all alerts for all clients of an MCC account. The " + - "effective user (ClientCustomerId or AuthToken) must be an MCC user to get results. " + - "This code example won't work with Test Accounts. See " + + "effective user (ClientCustomerId or OAuth2 header) must be an MCC user to get " + + "results. This code example won't work with Test Accounts. See " + "https://developers.google.com/adwords/api/docs/test-accounts"; } } diff --git a/examples/AdWords/CSharp/v201406/AccountManagement/GetAccountAlerts.cs b/examples/AdWords/CSharp/v201406/AccountManagement/GetAccountAlerts.cs index 3fc34ad5f04..f1b8f17bce0 100644 --- a/examples/AdWords/CSharp/v201406/AccountManagement/GetAccountAlerts.cs +++ b/examples/AdWords/CSharp/v201406/AccountManagement/GetAccountAlerts.cs @@ -24,8 +24,8 @@ namespace Google.Api.Ads.AdWords.Examples.CSharp.v201406 { /// /// This code example gets all alerts for all clients of an MCC account. - /// The effective user (ClientCustomerId or AuthToken) must be an MCC user - /// to get results. This code example won't work with Test Accounts. See + /// The effective user (ClientCustomerId or OAuth2 header) must be an MCC + /// user to get results. This code example won't work with Test Accounts. See /// https://developers.google.com/adwords/api/docs/test-accounts /// /// Tags: AlertService.get @@ -52,8 +52,8 @@ public static void Main(string[] args) { public override string Description { get { return "This code example gets all alerts for all clients of an MCC account. The " + - "effective user (ClientCustomerId or AuthToken) must be an MCC user to get results. " + - "This code example won't work with Test Accounts. See " + + "effective user (ClientCustomerId or OAuth2 header) must be an MCC user to get " + + "results. This code example won't work with Test Accounts. See " + "https://developers.google.com/adwords/api/docs/test-accounts"; } } diff --git a/examples/AdWords/Vb/AdWords.Examples.VB.vbproj b/examples/AdWords/Vb/AdWords.Examples.VB.vbproj index 4942bb517a5..5c85c6695be 100644 --- a/examples/AdWords/Vb/AdWords.Examples.VB.vbproj +++ b/examples/AdWords/Vb/AdWords.Examples.VB.vbproj @@ -117,7 +117,6 @@ - @@ -183,7 +182,6 @@ - diff --git a/examples/AdWords/Vb/App.config b/examples/AdWords/Vb/App.config index 1ee298baf62..a566c03c3c7 100644 --- a/examples/AdWords/Vb/App.config +++ b/examples/AdWords/Vb/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/examples/AdWords/Vb/Properties/AssemblyInfo.vb b/examples/AdWords/Vb/Properties/AssemblyInfo.vb index aea91f5571a..ea2f587d3cb 100644 --- a/examples/AdWords/Vb/Properties/AssemblyInfo.vb +++ b/examples/AdWords/Vb/Properties/AssemblyInfo.vb @@ -40,5 +40,5 @@ Imports System.Runtime.InteropServices - - \ No newline at end of file + + \ No newline at end of file diff --git a/examples/AdWords/Vb/v201402/AccountManagement/GetAccountAlerts.vb b/examples/AdWords/Vb/v201402/AccountManagement/GetAccountAlerts.vb index ab0b2ef77e9..08ab242cf7c 100644 --- a/examples/AdWords/Vb/v201402/AccountManagement/GetAccountAlerts.vb +++ b/examples/AdWords/Vb/v201402/AccountManagement/GetAccountAlerts.vb @@ -24,8 +24,8 @@ Imports System.IO Namespace Google.Api.Ads.AdWords.Examples.VB.v201402 ''' ''' This code example gets all alerts for all clients of an MCC account. - ''' The effective user (ClientCustomerId or AuthToken) must be an MCC user - ''' to get results. This code example won't work with Test Accounts. See + ''' The effective user (ClientCustomerId or OAuth2 header) must be an MCC + ''' user to get results. This code example won't work with Test Accounts. See ''' https://developers.google.com/adwords/api/docs/test-accounts. ''' ''' Tags: AlertService.get @@ -53,7 +53,7 @@ Namespace Google.Api.Ads.AdWords.Examples.VB.v201402 Public Overrides ReadOnly Property Description() As String Get Return "This code example gets all alerts for all clients of an MCC account. The " & _ - "effective user (ClientCustomerId or AuthToken) must be an MCC user to get " & _ + "effective user (ClientCustomerId or OAuth2 header) must be an MCC user to get " & _ "results. This code example won't work with Test Accounts. See " & _ "https://developers.google.com/adwords/api/docs/test-accounts" End Get diff --git a/examples/AdWords/Vb/v201402/ErrorHandling/HandleTwoFactorAuthorizationError.vb b/examples/AdWords/Vb/v201402/ErrorHandling/HandleTwoFactorAuthorizationError.vb deleted file mode 100644 index 132fef4177e..00000000000 --- a/examples/AdWords/Vb/v201402/ErrorHandling/HandleTwoFactorAuthorizationError.vb +++ /dev/null @@ -1,95 +0,0 @@ -' Copyright 2014, Google Inc. All Rights Reserved. -' -' Licensed under the Apache License, Version 2.0 (the "License"); -' you may not use this file except in compliance with the License. -' You may obtain a copy of the License at -' -' http://www.apache.org/licenses/LICENSE-2.0 -' -' Unless required by applicable law or agreed to in writing, software -' distributed under the License is distributed on an "AS IS" BASIS, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' See the License for the specific language governing permissions and -' limitations under the License. - -' Author: api.anash@gmail.com (Anash P. Oommen) - -Imports Google.Api.Ads.AdWords.Lib -Imports Google.Api.Ads.Common.Lib - -Imports System -Imports System.Collections.Generic -Imports System.IO - -Namespace Google.Api.Ads.AdWords.Examples.VB.v201402 - ''' - ''' This code example illustrates how to handle 2 factor authorization errors. - ''' - ''' Tags: CampaignService.get - ''' - Public Class HandleTwoFactorAuthorizationError - Inherits ExampleBase - ''' - ''' Main method, to run this code example as a standalone application. - ''' - ''' The command line arguments. - Public Shared Sub Main(ByVal args As String()) - Dim codeExample As New HandleTwoFactorAuthorizationError - Console.WriteLine(codeExample.Description) - Try - codeExample.Run(New AdWordsUser) - Catch ex As Exception - Console.WriteLine("An exception occurred while running this code example. {0}", _ - ExampleUtilities.FormatException(ex)) - End Try - End Sub - - ''' - ''' Returns a description about the code example. - ''' - ''' - Public Overrides ReadOnly Property Description() As String - Get - Return "This code example illustrates how to handle 2 factor authorization errors." - End Get - End Property - - ''' - ''' Runs the code example. - ''' - ''' The AdWords user. - Public Sub Run(ByVal user As AdWordsUser) - ' Use a test account for which 2 factor authentication has been enabled. - Dim loginEmail As String = "2steptester@gmail.com" - Dim password As String = "testaccount" - - Dim config As New AdWordsAppConfig - config.Email = loginEmail - config.Password = password - Dim authToken As New AuthToken(config, "adwords") - - Try - ' Try to obtain an authToken. - Dim token As String = authToken.GetToken - Console.WriteLine("Retrieved an authToken = {0} for user {1}.", token, loginEmail) - Catch ex As AuthTokenException - ' Since the test account has 2 factor authentication enabled, this block - ' of code will be executed. - If (ex.ErrorCode = AuthTokenErrorCode.BadAuthentication) Then - If (ex.Info = "InvalidSecondFactor") Then - Console.WriteLine("The user has enabled two factor authentication in this " & _ - "account. Have the user generate an application-specific password to make " & _ - "calls against the AdWords API. See " & _ - "http://adwordsapi.blogspot.com/2011/02/authentication-changes-with-2-step.html" & _ - "for more details.") - Else - Console.WriteLine("Invalid credentials.") - End If - Else - Throw New System.ApplicationException(String.Format("The server raised an {0} error.", _ - ex.ErrorCode), ex) - End If - End Try - End Sub - End Class -End Namespace diff --git a/examples/AdWords/Vb/v201406/AccountManagement/GetAccountAlerts.vb b/examples/AdWords/Vb/v201406/AccountManagement/GetAccountAlerts.vb index 8b632a18b78..6ce5e714a29 100644 --- a/examples/AdWords/Vb/v201406/AccountManagement/GetAccountAlerts.vb +++ b/examples/AdWords/Vb/v201406/AccountManagement/GetAccountAlerts.vb @@ -24,8 +24,8 @@ Imports System.IO Namespace Google.Api.Ads.AdWords.Examples.VB.v201406 ''' ''' This code example gets all alerts for all clients of an MCC account. - ''' The effective user (ClientCustomerId or AuthToken) must be an MCC user - ''' to get results. This code example won't work with Test Accounts. See + ''' The effective user (ClientCustomerId or OAuth2 header) must be an MCC + ''' user to get results. This code example won't work with Test Accounts. See ''' https://developers.google.com/adwords/api/docs/test-accounts. ''' ''' Tags: AlertService.get @@ -53,7 +53,7 @@ Namespace Google.Api.Ads.AdWords.Examples.VB.v201406 Public Overrides ReadOnly Property Description() As String Get Return "This code example gets all alerts for all clients of an MCC account. The " & _ - "effective user (ClientCustomerId or AuthToken) must be an MCC user to get " & _ + "effective user (ClientCustomerId or OAuth2 header) must be an MCC user to get " & _ "results. This code example won't work with Test Accounts. See " & _ "https://developers.google.com/adwords/api/docs/test-accounts" End Get diff --git a/examples/AdWords/Vb/v201406/ErrorHandling/HandleTwoFactorAuthorizationError.vb b/examples/AdWords/Vb/v201406/ErrorHandling/HandleTwoFactorAuthorizationError.vb deleted file mode 100644 index da6465d50c3..00000000000 --- a/examples/AdWords/Vb/v201406/ErrorHandling/HandleTwoFactorAuthorizationError.vb +++ /dev/null @@ -1,95 +0,0 @@ -' Copyright 2014, Google Inc. All Rights Reserved. -' -' Licensed under the Apache License, Version 2.0 (the "License"); -' you may not use this file except in compliance with the License. -' You may obtain a copy of the License at -' -' http://www.apache.org/licenses/LICENSE-2.0 -' -' Unless required by applicable law or agreed to in writing, software -' distributed under the License is distributed on an "AS IS" BASIS, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' See the License for the specific language governing permissions and -' limitations under the License. - -' Author: api.anash@gmail.com (Anash P. Oommen) - -Imports Google.Api.Ads.AdWords.Lib -Imports Google.Api.Ads.Common.Lib - -Imports System -Imports System.Collections.Generic -Imports System.IO - -Namespace Google.Api.Ads.AdWords.Examples.VB.v201406 - ''' - ''' This code example illustrates how to handle 2 factor authorization errors. - ''' - ''' Tags: CampaignService.get - ''' - Public Class HandleTwoFactorAuthorizationError - Inherits ExampleBase - ''' - ''' Main method, to run this code example as a standalone application. - ''' - ''' The command line arguments. - Public Shared Sub Main(ByVal args As String()) - Dim codeExample As New HandleTwoFactorAuthorizationError - Console.WriteLine(codeExample.Description) - Try - codeExample.Run(New AdWordsUser) - Catch ex As Exception - Console.WriteLine("An exception occurred while running this code example. {0}", _ - ExampleUtilities.FormatException(ex)) - End Try - End Sub - - ''' - ''' Returns a description about the code example. - ''' - ''' - Public Overrides ReadOnly Property Description() As String - Get - Return "This code example illustrates how to handle 2 factor authorization errors." - End Get - End Property - - ''' - ''' Runs the code example. - ''' - ''' The AdWords user. - Public Sub Run(ByVal user As AdWordsUser) - ' Use a test account for which 2 factor authentication has been enabled. - Dim loginEmail As String = "2steptester@gmail.com" - Dim password As String = "testaccount" - - Dim config As New AdWordsAppConfig - config.Email = loginEmail - config.Password = password - Dim authToken As New AuthToken(config, "adwords") - - Try - ' Try to obtain an authToken. - Dim token As String = authToken.GetToken - Console.WriteLine("Retrieved an authToken = {0} for user {1}.", token, loginEmail) - Catch ex As AuthTokenException - ' Since the test account has 2 factor authentication enabled, this block - ' of code will be executed. - If (ex.ErrorCode = AuthTokenErrorCode.BadAuthentication) Then - If (ex.Info = "InvalidSecondFactor") Then - Console.WriteLine("The user has enabled two factor authentication in this " & _ - "account. Have the user generate an application-specific password to make " & _ - "calls against the AdWords API. See " & _ - "http://adwordsapi.blogspot.com/2011/02/authentication-changes-with-2-step.html" & _ - "for more details.") - Else - Console.WriteLine("Invalid credentials.") - End If - Else - Throw New System.ApplicationException(String.Format("The server raised an {0} error.", _ - ex.ErrorCode), ex) - End If - End Try - End Sub - End Class -End Namespace diff --git a/examples/AdXBuyer/CSharp/App.config b/examples/AdXBuyer/CSharp/App.config index 1ee298baf62..a566c03c3c7 100644 --- a/examples/AdXBuyer/CSharp/App.config +++ b/examples/AdXBuyer/CSharp/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/examples/AdXBuyer/CSharp/OAuth/ConsoleExample.cs b/examples/AdXBuyer/CSharp/OAuth/ConsoleExample.cs index 4c6f7541c1c..bca23f4a7c5 100644 --- a/examples/AdXBuyer/CSharp/OAuth/ConsoleExample.cs +++ b/examples/AdXBuyer/CSharp/OAuth/ConsoleExample.cs @@ -48,7 +48,7 @@ namespace Google.Api.Ads.AdWords.Examples.CSharp.OAuth { /// /// 3. Replace the Main() method with this class's method. /// 4. Copy App.config from AdWords.Examples.CSharp project, and configure - /// it as shown in ths project's Web.config. + /// it as shown in ths project's App.config. /// 5. Compile and run this example. /// public class ConsoleExample { @@ -58,14 +58,17 @@ public class ConsoleExample { /// Command line arguments. static void Main(string[] args) { AdWordsUser user = new AdWordsUser(); - AdWordsAppConfig config = (user.Config as AdWordsAppConfig); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + + // This code example shows how to run an AdWords API web application + // while incorporating the OAuth2 installed application flow into your + // application. If your application uses a single MCC login to make calls + // to all your accounts, you shouldn't use this code example. Instead, you + // should run OAuthTokenGenerator.exe to generate a refresh + // token and use that configuration in your application's App.config. + AdWordsAppConfig config = user.Config as AdWordsAppConfig; + if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - DoAuth2Authorization(user); - } - } else { - throw new Exception("Authorization mode is not OAuth."); + DoAuth2Authorization(user); } Console.Write("Enter the customer id: "); diff --git a/examples/AdXBuyer/CSharp/OAuth/Default.aspx.cs b/examples/AdXBuyer/CSharp/OAuth/Default.aspx.cs index a110c7b78ae..65d2c212175 100644 --- a/examples/AdXBuyer/CSharp/OAuth/Default.aspx.cs +++ b/examples/AdXBuyer/CSharp/OAuth/Default.aspx.cs @@ -55,17 +55,12 @@ protected void OnAuthorizeButtonClick(object sender, EventArgs e) { // while incorporating the OAuth2 web application flow into your // application. If your application uses a single MCC login to make calls // to all your accounts, you shouldn't use this code example. Instead, you - // should run Common\Util\OAuth2TokenGenerator.cs to generate a refresh - // token and set that in user.Config.OAuth2RefreshToken field, or set - // OAuth2RefreshToken key in your App.config / Web.config. + // should run OAuthTokenGenerator.exe to generate a refresh + // token and use that configuration in your website's Web.config. AdWordsAppConfig config = user.Config as AdWordsAppConfig; - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - Response.Redirect("OAuthLogin.aspx"); - } - } else { - throw new Exception("Authorization mode is not OAuth."); + if (user.Config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { + Response.Redirect("OAuthLogin.aspx"); } } @@ -192,14 +187,9 @@ protected void OnGetCampaignsButtonClick(object sender, EventArgs e) { /// private void ConfigureUserForOAuth() { AdWordsAppConfig config = (user.Config as AdWordsAppConfig); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { + if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { user.OAuthProvider = (OAuth2ProviderForApplications) Session["OAuthProvider"]; - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - user.OAuthProvider = (OAuth2ProviderForApplications) Session["OAuthProvider"]; - } - } else { - throw new Exception("Authorization mode is not OAuth."); } } diff --git a/examples/AdXBuyer/CSharp/OAuth/OAuthLogin.aspx.cs b/examples/AdXBuyer/CSharp/OAuth/OAuthLogin.aspx.cs index 86ed1938f65..d7a9ad3b164 100644 --- a/examples/AdXBuyer/CSharp/OAuth/OAuthLogin.aspx.cs +++ b/examples/AdXBuyer/CSharp/OAuth/OAuthLogin.aspx.cs @@ -43,11 +43,9 @@ protected void Page_Load(object sender, EventArgs e) { // Create an AdWordsAppConfig object with the default settings in // App.config. AdWordsAppConfig config = new AdWordsAppConfig(); - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (config.OAuth2Mode == OAuth2Flow.APPLICATION && - string.IsNullOrEmpty(config.OAuth2RefreshToken)) { - DoAuth2Configuration(config); - } + if (config.OAuth2Mode == OAuth2Flow.APPLICATION && + string.IsNullOrEmpty(config.OAuth2RefreshToken)) { + DoAuth2Configuration(config); } } diff --git a/examples/AdXBuyer/CSharp/OAuth/Properties/Properties.cs b/examples/AdXBuyer/CSharp/OAuth/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/examples/AdXBuyer/CSharp/OAuth/Properties/Properties.cs +++ b/examples/AdXBuyer/CSharp/OAuth/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/examples/AdXBuyer/CSharp/OAuth/Web.config b/examples/AdXBuyer/CSharp/OAuth/Web.config index c140a7e5e84..e3afa35ff57 100644 --- a/examples/AdXBuyer/CSharp/OAuth/Web.config +++ b/examples/AdXBuyer/CSharp/OAuth/Web.config @@ -57,7 +57,6 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - - - - - - - diff --git a/examples/AdXBuyer/CSharp/Properties/Properties.cs b/examples/AdXBuyer/CSharp/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/examples/AdXBuyer/CSharp/Properties/Properties.cs +++ b/examples/AdXBuyer/CSharp/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/examples/AdXBuyer/Vb/App.config b/examples/AdXBuyer/Vb/App.config index 1ee298baf62..a566c03c3c7 100644 --- a/examples/AdXBuyer/Vb/App.config +++ b/examples/AdXBuyer/Vb/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/examples/AdXBuyer/Vb/Properties/AssemblyInfo.vb b/examples/AdXBuyer/Vb/Properties/AssemblyInfo.vb index aea91f5571a..ea2f587d3cb 100644 --- a/examples/AdXBuyer/Vb/Properties/AssemblyInfo.vb +++ b/examples/AdXBuyer/Vb/Properties/AssemblyInfo.vb @@ -40,5 +40,5 @@ Imports System.Runtime.InteropServices - - \ No newline at end of file + + \ No newline at end of file diff --git a/examples/Dfa/CSharp/App.config b/examples/Dfa/CSharp/App.config index 3a6bc204c19..df933a64532 100644 --- a/examples/Dfa/CSharp/App.config +++ b/examples/Dfa/CSharp/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-dfa-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -68,8 +68,8 @@ @@ -68,8 +68,8 @@ @@ -36,6 +36,10 @@ + + + @@ -77,8 +81,8 @@ @@ -56,8 +56,8 @@ @@ -91,7 +91,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/doubleclick-publishers/docs/service_accounts - and https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/src/AdWords/Headers/RequestHeader.cs b/src/AdWords/Headers/RequestHeader.cs index 7f45a6f9ea7..6d08aa497c0 100644 --- a/src/AdWords/Headers/RequestHeader.cs +++ b/src/AdWords/Headers/RequestHeader.cs @@ -55,18 +55,6 @@ protected set { } } - /// - /// Gets or sets the auth token. - /// - public string authToken { - get { - return stub.authToken; - } - set { - stub.authToken = value; - } - } - /// /// Gets or sets the client customer id. /// diff --git a/src/AdWords/Headers/RequestHeaderStub.cs b/src/AdWords/Headers/RequestHeaderStub.cs index a2c8a1fae36..a67798f397b 100644 --- a/src/AdWords/Headers/RequestHeaderStub.cs +++ b/src/AdWords/Headers/RequestHeaderStub.cs @@ -26,18 +26,6 @@ namespace Google.Api.Ads.AdWords.Headers { [XmlRootAttribute(ElementName = "RequestHeader", Namespace = "https://adwords.google.com/api/adwords{gp}{version}")] public class RequestHeaderStub { - /// - /// Auth token to authenticate the API call. - /// - [XmlElementAttribute(Namespace = "https://adwords.google.com/api/adwords/cm{version}")] - public string authToken; - - /// - /// Application token. - /// - [XmlElementAttribute(Namespace = "https://adwords.google.com/api/adwords/cm{version}")] - [Obsolete("AdWords API no longer requires application tokens.")] - public string applicationToken; /// /// Developer token. @@ -51,12 +39,6 @@ public class RequestHeaderStub { [XmlElementAttribute(Namespace = "https://adwords.google.com/api/adwords/cm{version}")] public string clientCustomerId; - /// - /// Client email for which API calls are made. - /// - [XmlElementAttribute(Namespace = "https://adwords.google.com/api/adwords/cm{version}")] - public string clientEmail; - /// /// User agent to identify the requesting application. /// diff --git a/src/AdWords/Lib/AdWordsAppConfig.cs b/src/AdWords/Lib/AdWordsAppConfig.cs index 30bcd12499b..942b11f7291 100644 --- a/src/AdWords/Lib/AdWordsAppConfig.cs +++ b/src/AdWords/Lib/AdWordsAppConfig.cs @@ -79,12 +79,6 @@ public class AdWordsAppConfig : AppConfigBase { /// private const string DEFAULT_ADWORDSAPI_SERVER = "https://adwords.google.com"; - /// - /// Default value for authorizationMethod. - /// - private const AdWordsAuthorizationMethod DEFAULT_AUTHORIZATION_METHOD = - AdWordsAuthorizationMethod.OAuth2; - /// /// Default OAuth2 scope for AdWords API. /// @@ -125,11 +119,6 @@ public class AdWordsAppConfig : AppConfigBase { /// private string adWordsApiServer; - /// - /// Authorization method to be used when making API calls. - /// - private AdWordsAuthorizationMethod authorizationMethod; - /// /// Gets or sets the client customerId to be used in SOAP headers. /// @@ -214,18 +203,6 @@ public string AdWordsApiServer { } } - /// - /// Gets or sets the authorization method to be used when making API calls. - /// - public AdWordsAuthorizationMethod AuthorizationMethod { - get { - return authorizationMethod; - } - set { - SetPropertyField("AuthorizationMethod", ref authorizationMethod, value); - } - } - /// /// Gets a useragent string that can be used with the library. /// @@ -252,7 +229,6 @@ public AdWordsAppConfig() : base() { placesLoginEmail = ""; userAgent = ""; adWordsApiServer = DEFAULT_ADWORDSAPI_SERVER; - authorizationMethod = DEFAULT_AUTHORIZATION_METHOD; ReadSettings((Hashtable) ConfigurationManager.GetSection("AdWordsApi")); } @@ -277,13 +253,6 @@ protected override void ReadSettings(Hashtable settings) { userAgent = ReadSetting(settings, USER_AGENT, userAgent); adWordsApiServer = ReadSetting(settings, ADWORDSAPI_SERVER, adWordsApiServer); - try { - authorizationMethod = (AdWordsAuthorizationMethod) Enum.Parse( - typeof(AdWordsAuthorizationMethod), - ReadSetting(settings, AUTHORIZATION_METHOD, authorizationMethod.ToString())); - } catch { - authorizationMethod = DEFAULT_AUTHORIZATION_METHOD; - } // If there is an OAuth2 scope mentioned in App.config, this will be // loaded by the above call. If there isn't one, we will initialize it diff --git a/src/AdWords/Lib/AdWordsAuthorizationMethod.cs b/src/AdWords/Lib/AdWordsAuthorizationMethod.cs deleted file mode 100644 index 2da389c931c..00000000000 --- a/src/AdWords/Lib/AdWordsAuthorizationMethod.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2011, Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Author: api.anash@gmail.com (Anash P. Oommen) - -namespace Google.Api.Ads.AdWords.Lib { - /// - /// List of supported Authorization methods for AdWords API. - /// - public enum AdWordsAuthorizationMethod { - /// - /// ClientLogin API. - /// - ClientLogin, - - /// - /// OAuth 2.0 API. - /// - OAuth2 - } -} diff --git a/src/AdWords/Lib/AdWordsErrorHandler.cs b/src/AdWords/Lib/AdWordsErrorHandler.cs index 38ab09cde90..2ee9a377873 100644 --- a/src/AdWords/Lib/AdWordsErrorHandler.cs +++ b/src/AdWords/Lib/AdWordsErrorHandler.cs @@ -90,13 +90,7 @@ public override bool ShouldRetry(Exception ex) { public override void PrepareForRetry(Exception ex) { try { if (ex is AdWordsCredentialsExpiredException) { - AdWordsCredentialsExpiredException e = (AdWordsCredentialsExpiredException) ex; - if (this.Config.AuthorizationMethod == AdWordsAuthorizationMethod.ClientLogin) { - AuthToken.Cache.InvalidateToken(e.ExpiredCredential); - Config.AuthToken = null; - } else if (this.Config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - this.user.OAuthProvider.RefreshAccessToken(); - } + this.user.OAuthProvider.RefreshAccessToken(); } else if (IsTransientError(ex)) { DoExponentialBackoff(); } @@ -125,22 +119,6 @@ public static bool IsExpiredCredentialsError(Exception ex) { return ex is AdWordsCredentialsExpiredException; } - /// - /// Determines whether the exception thrown by the server is an AuthToken - /// Invalid Error. - /// - /// The exception. - /// True, if the server exception is a AuthToken invalid error, - /// false otherwise. - public static bool IsCookieInvalidError(Exception ex) { - if (ex is AdWordsApiException) { - return MatchesError((AdWordsApiException) ex, new string[] {COOKIE_INVALID_ERROR}); - } else if (ex is ReportsException) { - return MatchesError((ReportsException) ex, new string[] {COOKIE_INVALID_ERROR}); - } - return false; - } - /// /// Determines whether the exception thrown by the server is an OAuth token /// expired error. diff --git a/src/AdWords/Lib/AdWordsServiceFactory.cs b/src/AdWords/Lib/AdWordsServiceFactory.cs index d44e754ca35..efce44d57f3 100644 --- a/src/AdWords/Lib/AdWordsServiceFactory.cs +++ b/src/AdWords/Lib/AdWordsServiceFactory.cs @@ -34,8 +34,6 @@ namespace Google.Api.Ads.AdWords.Lib { /// public class AdWordsServiceFactory : ServiceFactory { - private const string FINAL_CLIENT_LOGIN_VERSION = "v201309"; - /// /// The request header to be used with AdWords API services. /// @@ -162,16 +160,6 @@ protected override void CheckServicePreconditions(ServiceSignature signature) { throw new InvalidCastException(string.Format(CultureInfo.InvariantCulture, AdWordsErrorMessages.SignatureIsOfWrongType, typeof(AdWordsServiceSignature))); } - - AdWordsAppConfig adWordsAppConfig = (AdWordsAppConfig) Config; - AdWordsServiceSignature adWordsSingature = signature as AdWordsServiceSignature; - String version = adWordsSingature.Version; - if (adWordsAppConfig.AuthorizationMethod == AdWordsAuthorizationMethod.ClientLogin - && version.CompareTo(FINAL_CLIENT_LOGIN_VERSION) > 0) { - throw new AdWordsException(string.Format(AdWordsErrorMessages.ClientLoginNotSupported, - version)); - } } - } } diff --git a/src/AdWords/Lib/AdWordsSoapClient.cs b/src/AdWords/Lib/AdWordsSoapClient.cs index 5f3e1d4dca1..24449d271e9 100644 --- a/src/AdWords/Lib/AdWordsSoapClient.cs +++ b/src/AdWords/Lib/AdWordsSoapClient.cs @@ -46,7 +46,6 @@ public class AdWordsSoapClient : AdsSoapClient { /// The method parameters. protected override void InitForCall(string methodName, object[] parameters) { AdWordsAppConfig config = this.User.Config as AdWordsAppConfig; - string oAuthHeader = null; RequestHeader header = GetRequestHeader(); if (string.IsNullOrEmpty(header.developerToken)) { @@ -57,19 +56,11 @@ protected override void InitForCall(string methodName, object[] parameters) { TraceUtilities.WriteGeneralWarnings(AdWordsErrorMessages.ClientCustomerIdIsEmpty); } - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (this.User.OAuthProvider != null) { - oAuthHeader = this.User.OAuthProvider.GetAuthHeader(); - } else { - throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull); - } - } else if (config.AuthorizationMethod == AdWordsAuthorizationMethod.ClientLogin) { - if (header != null) { - header.authToken = (!string.IsNullOrEmpty(config.AuthToken)) ? config.AuthToken : - new AuthToken(config, SERVICE_NAME).GetToken(); - } else { - throw new AdWordsApiException(null, AdWordsErrorMessages.FailedToSetAuthorizationHeader); - } + string oAuthHeader = null; + if (this.User.OAuthProvider != null) { + oAuthHeader = this.User.OAuthProvider.GetAuthHeader(); + } else { + throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull); } ContextStore.AddKey("OAuthHeader", oAuthHeader); base.InitForCall(methodName, parameters); @@ -140,9 +131,7 @@ protected override Exception GetCustomException(SoapException ex) { faultNode.OuterXml, Assembly.GetExecutingAssembly().GetType( this.GetType().Namespace + ".ApiException"), defaultNs, "ApiExceptionFault"), AdWordsErrorMessages.AnApiExceptionOccurred, ex); - if (AdWordsErrorHandler.IsCookieInvalidError(awapiException)) { - return new AdWordsCredentialsExpiredException(this.GetRequestHeader().authToken); - } else if (AdWordsErrorHandler.IsOAuthTokenExpiredError(awapiException)) { + if (AdWordsErrorHandler.IsOAuthTokenExpiredError(awapiException)) { return new AdWordsCredentialsExpiredException( (string) ContextStore.GetValue("OAuthHeader")); } else { diff --git a/src/AdWords/Lib/AdWordsTraceListener.cs b/src/AdWords/Lib/AdWordsTraceListener.cs index 40223d157f2..3c98bfb0518 100644 --- a/src/AdWords/Lib/AdWordsTraceListener.cs +++ b/src/AdWords/Lib/AdWordsTraceListener.cs @@ -18,6 +18,7 @@ using Google.Api.Ads.Common.Util; using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Net; @@ -111,8 +112,9 @@ protected override string FormatHttpResponse(string soapResponse) { /// Gets a list of fields to be masked in xml logs. /// /// The list of fields to be masked. - protected override string[] GetFieldsToMask() { - return new string[] {"password", "developerToken", "applicationToken", "authToken"}; + protected override ISet GetFieldsToMask() { + return new HashSet(new string[] { "developerToken", "Authorization" }, + StringComparer.OrdinalIgnoreCase); } } } diff --git a/src/AdWords/Properties/Properties.cs b/src/AdWords/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/src/AdWords/Properties/Properties.cs +++ b/src/AdWords/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/src/AdWords/Util/Reports/ReportUtilities.cs b/src/AdWords/Util/Reports/ReportUtilities.cs index 715bf58acb2..df7499d4efe 100644 --- a/src/AdWords/Util/Reports/ReportUtilities.cs +++ b/src/AdWords/Util/Reports/ReportUtilities.cs @@ -61,12 +61,6 @@ public class ReportUtilities { /// private const string ADHOC_REPORT_URL_FORMAT = "{0}/api/adwords/reportdownload/{1}"; - /// - /// The Authorization header prefix to be used when Authorization method is - /// ClientLogin. - /// - private const string CLIENT_LOGIN_PREFIX = "GoogleLogin auth="; - /// /// Last version that supported returnMoneyInMicros header. /// @@ -305,10 +299,7 @@ private void DownloadReportToStream(string downloadUrl, bool? returnMoneyInMicro reportsException = ParseException(exceptionBody); } - if (AdWordsErrorHandler.IsCookieInvalidError(reportsException)) { - reportsException = new AdWordsCredentialsExpiredException( - request.Headers["Authorization"].Replace(CLIENT_LOGIN_PREFIX, "")); - } else if (AdWordsErrorHandler.IsOAuthTokenExpiredError(reportsException)) { + if (AdWordsErrorHandler.IsOAuthTokenExpiredError(reportsException)) { reportsException = new AdWordsCredentialsExpiredException( request.Headers["Authorization"]); } @@ -365,16 +356,10 @@ private HttpWebRequest BuildRequest(string downloadUrl, bool? returnMoneyInMicro } else { (request as HttpWebRequest).AutomaticDecompression = DecompressionMethods.None; } - if (config.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { - if (this.User.OAuthProvider != null) { - request.Headers["Authorization"] = this.User.OAuthProvider.GetAuthHeader(); - } else { - throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull); - } - } else if (config.AuthorizationMethod == AdWordsAuthorizationMethod.ClientLogin) { - string authToken = (!string.IsNullOrEmpty(config.AuthToken)) ? config.AuthToken : - new AuthToken(config, AdWordsSoapClient.SERVICE_NAME).GetToken(); - request.Headers["Authorization"] = CLIENT_LOGIN_PREFIX + authToken; + if (this.User.OAuthProvider != null) { + request.Headers["Authorization"] = this.User.OAuthProvider.GetAuthHeader(); + } else { + throw new AdWordsApiException(null, AdWordsErrorMessages.OAuthProviderCannotBeNull); } if (returnMoneyInMicros.HasValue) { diff --git a/src/Common/Lib/TraceListener.cs b/src/Common/Lib/TraceListener.cs index c3207bce24d..bef8b4b82bb 100644 --- a/src/Common/Lib/TraceListener.cs +++ b/src/Common/Lib/TraceListener.cs @@ -17,23 +17,24 @@ using Google.Api.Ads.Common.Util; using System; +using System.Collections.Generic; using System.Globalization; -using System.IO; using System.Net; -using System.Runtime.Remoting.Messaging; using System.Text; -using System.Threading; -using System.Web; -using System.Web.Services; -using System.Web.Services.Protocols; using System.Xml; -using System.Xml.Serialization; namespace Google.Api.Ads.Common.Lib { + /// /// Listens to SOAP messages sent and received by this library. /// public abstract class TraceListener : SoapListener { + + /// + /// The mask pattern to be used when masking sensitive data in logs. + /// + private const string MASK_PATTERN = "******"; + /// /// The config class to be used with this class. /// @@ -133,7 +134,7 @@ private void PerformLogging(AdsClient service, string soapRequest, string soapRe /// Gets a list of fields to be masked in xml logs. /// /// The list of fields to be masked. - protected abstract string[] GetFieldsToMask(); + protected abstract ISet GetFieldsToMask(); /// /// Creates a formatted http request text, to be written into HTTP logs. @@ -169,9 +170,19 @@ protected virtual string FormatSoapRequest(WebRequest webRequest, string soapReq headerBuilder.AppendFormat("{0} {1}\r\n", webRequest.Method, webRequest.RequestUri.AbsolutePath); + + ISet fieldsToMask = GetFieldsToMask(); + foreach (string key in webRequest.Headers) { - headerBuilder.AppendFormat("{0}: {1}\r\n", key, webRequest.Headers[key]); + string value = webRequest.Headers[key]; + if (config.MaskCredentials) { + if (fieldsToMask.Contains(key)) { + value = MASK_PATTERN; + } + } + headerBuilder.AppendFormat("{0}: {1}\r\n", key, value); } + headerBuilder.AppendFormat("TimeStamp: {0}\r\n", this.GetTimeStamp()); builder.AppendFormat("\r\n{0}\r\n", AppendHeadersToSoapXml(soapRequest, headerBuilder.ToString())); @@ -232,19 +243,17 @@ protected string AppendHeadersToSoapXml(string soapRequest, string headers) { /// The SOAP message, loaded as an XmlDocument. /// /// The list of field names to be masked. - protected void MaskCredentialsInLogs(XmlDocument soapMessageXml, string[] fieldNames) { + protected void MaskCredentialsInLogs(XmlDocument soapMessageXml, ISet fieldNames) { XmlNamespaceManager xmlns = new XmlNamespaceManager(soapMessageXml.NameTable); xmlns.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); XmlNodeList nodes = soapMessageXml.SelectNodes("soap:Envelope/soap:Header/descendant::*", xmlns); foreach (XmlElement node in nodes) { - if (Array.Exists(fieldNames, delegate(string match) { - return string.Compare(match, node.LocalName, true) == 0; - })) { - node.InnerText = "******"; + if (fieldNames.Contains(node.LocalName)) { + node.InnerText = MASK_PATTERN; } } } } -} +} \ No newline at end of file diff --git a/src/Dfa/App.config b/src/Dfa/App.config index 3a6bc204c19..df933a64532 100644 --- a/src/Dfa/App.config +++ b/src/Dfa/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-dfa-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -68,8 +68,8 @@ @@ -56,8 +56,8 @@ @@ -91,7 +91,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/doubleclick-publishers/docs/service_accounts - and https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/tests/AdWords/ExampleTestsBase.cs b/tests/AdWords/ExampleTestsBase.cs index 9978cbba6f8..64663473c81 100644 --- a/tests/AdWords/ExampleTestsBase.cs +++ b/tests/AdWords/ExampleTestsBase.cs @@ -37,13 +37,6 @@ public class ExampleTestsBase { /// protected AdWordsUser user = new AdWordsUser(); - /// - /// The interceptor for ClientLogin requests when running mocked code - /// examples. - /// - protected ClientLoginRequestInterceptor clientLoginInterceptor = - ClientLoginRequestInterceptor.Instance as ClientLoginRequestInterceptor; - /// /// The interceptor for AdWords API requests when running mocked code /// examples. @@ -74,24 +67,20 @@ protected void RunMockedExample(ExamplesMockData mockData, TestDelegate exampleD WebRequestInterceptor.OnBeforeSendResponse callback) { TextWriter oldWriter = Console.Out; try { - clientLoginInterceptor.Intercept = true; - clientLoginInterceptor.RaiseException = false; awapiInterceptor.Intercept = true; - AuthToken.Cache.Clear(); awapiInterceptor.LoadMessages(mockData.MockMessages, delegate(Uri requestUri, WebHeaderCollection headers, String body) { + VerifyHttpHeaders(headers); VerifySoapHeaders(requestUri, body); callback(requestUri, headers, body); } ); StringWriter newWriter = new StringWriter(); Console.SetOut(newWriter); - AdWordsAppConfig config = (user.Config as AdWordsAppConfig); exampleDelegate.Invoke(); Assert.AreEqual(newWriter.ToString().Trim(), mockData.ExpectedOutput.Trim()); } finally { Console.SetOut(oldWriter); - clientLoginInterceptor.Intercept = false; awapiInterceptor.Intercept = false; } } @@ -107,7 +96,6 @@ protected void RunExample(TestDelegate exampleDelegate) { Assert.DoesNotThrow(delegate() { TextWriter oldWriter = Console.Out; Console.SetOut(writer); - AuthToken.Cache.Clear(); exampleDelegate.Invoke(); Console.SetOut(oldWriter); Console.WriteLine(writer.ToString()); @@ -135,6 +123,23 @@ protected ExamplesMockData LoadMockData(string mockData) { InnerText); } + /// + /// Sets the mock OAuth2 tokens. + /// + protected void SetMockOAuth2Tokens() { + user.OAuthProvider.UpdatedOn = DateTime.Now; + user.OAuthProvider.ExpiresIn = int.Parse(OAuth2RequestInterceptor.EXPIRES_IN); + user.OAuthProvider.AccessToken = OAuth2RequestInterceptor.TEST_ACCESS_TOKEN; + } + + /// + /// Verifies the HTTP headers. + /// + /// The HTTP headers. + protected void VerifyHttpHeaders(WebHeaderCollection headers) { + Assert.AreEqual(headers["Authorization"], user.OAuthProvider.GetAuthHeader()); + } + /// /// Verifies the SOAP headers. /// @@ -155,10 +160,6 @@ protected void VerifySoapHeaders(Uri requestUri, string requestBody) { Assert.AreEqual(requestHeaders.Name, "RequestHeader"); foreach (XmlElement childNode in requestHeaders.ChildNodes) { switch (childNode.Name) { - case "authToken": - Assert.AreEqual(childNode.InnerText, "AUTH_TOKEN"); - break; - case "developerToken": Assert.AreEqual(childNode.InnerText, config.DeveloperToken); break; diff --git a/tests/AdWords/Lib/AdWordsServiceFactoryTests.cs b/tests/AdWords/Lib/AdWordsServiceFactoryTests.cs index 47669cd13a3..b10859f6fb4 100644 --- a/tests/AdWords/Lib/AdWordsServiceFactoryTests.cs +++ b/tests/AdWords/Lib/AdWordsServiceFactoryTests.cs @@ -28,8 +28,7 @@ namespace Google.Api.Ads.AdWords.Tests.Lib { /// [TestFixture] class AdWordsServiceFactoryTests { - private const string DEPRECATED_CLIENT_LOGIN_VERSION = "v201402"; - private const string SUPPORTED_CLIENT_LOGIN_VERSION = "v201309"; + private const string TEST_API_VERSION = "v201406"; private const string TEST_SERVICE = "MediaService"; private const string TEST_GROUP_NAME = "express"; @@ -51,62 +50,13 @@ public void Init() { } /// - /// Test that creating a service using ClientLogin in a deprecated version - /// throws an exception + /// Test creating a service using OAuth2. /// [Test] - [ExpectedException(typeof(AdWordsException))] - public void TestCreateServiceClientLoginDeprecated() { - ConfigureForClientLogin(); - serviceSignature = new AdWordsServiceSignature(DEPRECATED_CLIENT_LOGIN_VERSION, + public void TestCreateService() { + serviceSignature = new AdWordsServiceSignature(TEST_API_VERSION, TEST_SERVICE, TEST_GROUP_NAME); serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); } - - /// - /// Test that creating a service using ClientLogin in a supported version does not - /// throw an exception - /// - [Test] - public void TestCreateServiceClientLoginSupported() { - ConfigureForClientLogin(); - serviceSignature = new AdWordsServiceSignature(SUPPORTED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - /// - /// Test creating a service using OAuth2 in a version where ClientLogin is supported - /// - [Test] - public void TestCreateServiceOAuth2ClientLoginSupported() { - ConfigureForOAuth2(); - serviceSignature = new AdWordsServiceSignature(SUPPORTED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - /// - /// Test creating a service using OAuth2 in a version where ClientLogin is deprecated - /// - [Test] - public void TestCreateServiceOAuth2ClientLoginDeprecated() { - ConfigureForOAuth2(); - serviceSignature = new AdWordsServiceSignature(DEPRECATED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - private void ConfigureForOAuth2() { - AdWordsAppConfig config = new AdWordsAppConfig(); - config.AuthorizationMethod = AdWordsAuthorizationMethod.OAuth2; - serviceFactory.Config = config; - } - - private void ConfigureForClientLogin() { - AdWordsAppConfig config = new AdWordsAppConfig(); - config.AuthorizationMethod = AdWordsAuthorizationMethod.ClientLogin; - serviceFactory.Config = config; - } } } diff --git a/tests/AdWords/Properties/Properties.cs b/tests/AdWords/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/tests/AdWords/Properties/Properties.cs +++ b/tests/AdWords/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/tests/AdWords/Resources/GetAccountAlerts.v201402.txt b/tests/AdWords/Resources/GetAccountAlerts.v201402.txt index 3bf1e44f920..17a97284dc8 100644 --- a/tests/AdWords/Resources/GetAccountAlerts.v201402.txt +++ b/tests/AdWords/Resources/GetAccountAlerts.v201402.txt @@ -1,7 +1,7 @@ - <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201402"><authToken xmlns="https://adwords.google.com/api/adwords/cm/v201402">******</authToken><developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201402">******</developerToken><userAgent xmlns="https://adwords.google.com/api/adwords/cm/v201402">INSERT_YOUR_COMPANY_OR_APPLICATION_NAME_HERE (AwApi-DotNet/15.1.0, Common-Dotnet/1.4.0, .NET CLR/2.0.50727.5456)</userAgent></RequestHeader></soap:Header><soap:Body><get xmlns="https://adwords.google.com/api/adwords/mcm/v201402"><selector><query><clientSpec>ALL</clientSpec><filterSpec>ALL</filterSpec><types>ACCOUNT_ON_TARGET</types><types>DECLINED_PAYMENT</types><types>CREDIT_CARD_EXPIRING</types><types>ACCOUNT_BUDGET_ENDING</types><types>CAMPAIGN_ENDING</types><types>PAYMENT_NOT_ENTERED</types><types>MISSING_BANK_REFERENCE_NUMBER</types><types>CAMPAIGN_ENDED</types><types>ACCOUNT_BUDGET_BURN_RATE</types><types>USER_INVITE_PENDING</types><types>USER_INVITE_ACCEPTED</types><types>MANAGER_LINK_PENDING</types><types>ZERO_DAILY_SPENDING_LIMIT</types><types>TV_ACCOUNT_ON_TARGET</types><types>TV_ACCOUNT_BUDGET_ENDING</types><types>TV_ZERO_DAILY_SPENDING_LIMIT</types><types>UNKNOWN</types><severities>GREEN</severities><severities>YELLOW</severities><severities>RED</severities><triggerTimeSpec>ALL_TIME</triggerTimeSpec></query><paging><startIndex xmlns="https://adwords.google.com/api/adwords/cm/v201402">0</startIndex><numberResults xmlns="https://adwords.google.com/api/adwords/cm/v201402">500</numberResults></paging></selector></get></soap:Body></soap:Envelope> + <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201402"><developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201402">******</developerToken><userAgent xmlns="https://adwords.google.com/api/adwords/cm/v201402">INSERT_YOUR_COMPANY_OR_APPLICATION_NAME_HERE (AwApi-DotNet/15.1.0, Common-Dotnet/1.4.0, .NET CLR/2.0.50727.5456)</userAgent></RequestHeader></soap:Header><soap:Body><get xmlns="https://adwords.google.com/api/adwords/mcm/v201402"><selector><query><clientSpec>ALL</clientSpec><filterSpec>ALL</filterSpec><types>ACCOUNT_ON_TARGET</types><types>DECLINED_PAYMENT</types><types>CREDIT_CARD_EXPIRING</types><types>ACCOUNT_BUDGET_ENDING</types><types>CAMPAIGN_ENDING</types><types>PAYMENT_NOT_ENTERED</types><types>MISSING_BANK_REFERENCE_NUMBER</types><types>CAMPAIGN_ENDED</types><types>ACCOUNT_BUDGET_BURN_RATE</types><types>USER_INVITE_PENDING</types><types>USER_INVITE_ACCEPTED</types><types>MANAGER_LINK_PENDING</types><types>ZERO_DAILY_SPENDING_LIMIT</types><types>TV_ACCOUNT_ON_TARGET</types><types>TV_ACCOUNT_BUDGET_ENDING</types><types>TV_ZERO_DAILY_SPENDING_LIMIT</types><types>UNKNOWN</types><severities>GREEN</severities><severities>YELLOW</severities><severities>RED</severities><triggerTimeSpec>ALL_TIME</triggerTimeSpec></query><paging><startIndex xmlns="https://adwords.google.com/api/adwords/cm/v201402">0</startIndex><numberResults xmlns="https://adwords.google.com/api/adwords/cm/v201402">500</numberResults></paging></selector></get></soap:Body></soap:Envelope> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201402" xmlns="https://adwords.google.com/api/adwords/mcm/v201402"><ns2:requestId>0004cd7c5357ea800a837b1100006fdf</ns2:requestId><ns2:serviceName>AlertService</ns2:serviceName><ns2:methodName>get</ns2:methodName><ns2:operations>2</ns2:operations><ns2:responseTime>464</ns2:responseTime><ns2:units>2</ns2:units></ResponseHeader></soap:Header><soap:Body><getResponse xmlns="https://adwords.google.com/api/adwords/mcm/v201402" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201402"><rval><ns2:totalNumEntries>2</ns2:totalNumEntries><ns2:Page.Type>AlertPage</ns2:Page.Type><entries><alertSeverity>RED</alertSeverity><alertType>PAYMENT_NOT_ENTERED</alertType><clientCustomerId>1234567890</clientCustomerId><details><triggerTime>20121101 162410 PST8PDT</triggerTime></details></entries><entries><alertSeverity>RED</alertSeverity><alertType>PAYMENT_NOT_ENTERED</alertType><clientCustomerId>1234567890</clientCustomerId><details><triggerTime>20121101 162433 PST8PDT</triggerTime></details></entries></rval></getResponse></soap:Body></soap:Envelope> 1) Customer Id is 123-456-7890, Alert type is 'PAYMENT_NOT_ENTERED', Severity is RED diff --git a/tests/AdWords/Resources/GetAccountAlerts.v201406.txt b/tests/AdWords/Resources/GetAccountAlerts.v201406.txt index 52730ec32be..e473146033d 100644 --- a/tests/AdWords/Resources/GetAccountAlerts.v201406.txt +++ b/tests/AdWords/Resources/GetAccountAlerts.v201406.txt @@ -1,7 +1,7 @@ - <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201406"><authToken xmlns="https://adwords.google.com/api/adwords/cm/v201406">******</authToken><developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201406">******</developerToken><userAgent xmlns="https://adwords.google.com/api/adwords/cm/v201406">INSERT_YOUR_COMPANY_OR_APPLICATION_NAME_HERE (AwApi-DotNet/15.1.0, Common-Dotnet/1.4.0, .NET CLR/2.0.50727.5456)</userAgent></RequestHeader></soap:Header><soap:Body><get xmlns="https://adwords.google.com/api/adwords/mcm/v201406"><selector><query><clientSpec>ALL</clientSpec><filterSpec>ALL</filterSpec><types>ACCOUNT_ON_TARGET</types><types>DECLINED_PAYMENT</types><types>CREDIT_CARD_EXPIRING</types><types>ACCOUNT_BUDGET_ENDING</types><types>CAMPAIGN_ENDING</types><types>PAYMENT_NOT_ENTERED</types><types>MISSING_BANK_REFERENCE_NUMBER</types><types>CAMPAIGN_ENDED</types><types>ACCOUNT_BUDGET_BURN_RATE</types><types>USER_INVITE_PENDING</types><types>USER_INVITE_ACCEPTED</types><types>MANAGER_LINK_PENDING</types><types>ZERO_DAILY_SPENDING_LIMIT</types><types>TV_ACCOUNT_ON_TARGET</types><types>TV_ACCOUNT_BUDGET_ENDING</types><types>TV_ZERO_DAILY_SPENDING_LIMIT</types><types>UNKNOWN</types><severities>GREEN</severities><severities>YELLOW</severities><severities>RED</severities><triggerTimeSpec>ALL_TIME</triggerTimeSpec></query><paging><startIndex xmlns="https://adwords.google.com/api/adwords/cm/v201406">0</startIndex><numberResults xmlns="https://adwords.google.com/api/adwords/cm/v201406">500</numberResults></paging></selector></get></soap:Body></soap:Envelope> + <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201406"><developerToken xmlns="https://adwords.google.com/api/adwords/cm/v201406">******</developerToken><userAgent xmlns="https://adwords.google.com/api/adwords/cm/v201406">INSERT_YOUR_COMPANY_OR_APPLICATION_NAME_HERE (AwApi-DotNet/15.1.0, Common-Dotnet/1.4.0, .NET CLR/2.0.50727.5456)</userAgent></RequestHeader></soap:Header><soap:Body><get xmlns="https://adwords.google.com/api/adwords/mcm/v201406"><selector><query><clientSpec>ALL</clientSpec><filterSpec>ALL</filterSpec><types>ACCOUNT_ON_TARGET</types><types>DECLINED_PAYMENT</types><types>CREDIT_CARD_EXPIRING</types><types>ACCOUNT_BUDGET_ENDING</types><types>CAMPAIGN_ENDING</types><types>PAYMENT_NOT_ENTERED</types><types>MISSING_BANK_REFERENCE_NUMBER</types><types>CAMPAIGN_ENDED</types><types>ACCOUNT_BUDGET_BURN_RATE</types><types>USER_INVITE_PENDING</types><types>USER_INVITE_ACCEPTED</types><types>MANAGER_LINK_PENDING</types><types>ZERO_DAILY_SPENDING_LIMIT</types><types>TV_ACCOUNT_ON_TARGET</types><types>TV_ACCOUNT_BUDGET_ENDING</types><types>TV_ZERO_DAILY_SPENDING_LIMIT</types><types>UNKNOWN</types><severities>GREEN</severities><severities>YELLOW</severities><severities>RED</severities><triggerTimeSpec>ALL_TIME</triggerTimeSpec></query><paging><startIndex xmlns="https://adwords.google.com/api/adwords/cm/v201406">0</startIndex><numberResults xmlns="https://adwords.google.com/api/adwords/cm/v201406">500</numberResults></paging></selector></get></soap:Body></soap:Envelope> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><ResponseHeader xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201406" xmlns="https://adwords.google.com/api/adwords/mcm/v201406"><ns2:requestId>0004cd7c5357ea800a837b1100006fdf</ns2:requestId><ns2:serviceName>AlertService</ns2:serviceName><ns2:methodName>get</ns2:methodName><ns2:operations>2</ns2:operations><ns2:responseTime>464</ns2:responseTime><ns2:units>2</ns2:units></ResponseHeader></soap:Header><soap:Body><getResponse xmlns="https://adwords.google.com/api/adwords/mcm/v201406" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201406"><rval><ns2:totalNumEntries>2</ns2:totalNumEntries><ns2:Page.Type>AlertPage</ns2:Page.Type><entries><alertSeverity>RED</alertSeverity><alertType>PAYMENT_NOT_ENTERED</alertType><clientCustomerId>1234567890</clientCustomerId><details><triggerTime>20121101 162410 PST8PDT</triggerTime></details></entries><entries><alertSeverity>RED</alertSeverity><alertType>PAYMENT_NOT_ENTERED</alertType><clientCustomerId>1234567890</clientCustomerId><details><triggerTime>20121101 162433 PST8PDT</triggerTime></details></entries></rval></getResponse></soap:Body></soap:Envelope> 1) Customer Id is 123-456-7890, Alert type is 'PAYMENT_NOT_ENTERED', Severity is RED diff --git a/tests/AdWords/SoapMessages.v201402.Designer.cs b/tests/AdWords/SoapMessages.v201402.Designer.cs index bfb6387eb93..40b01d5ef9f 100644 --- a/tests/AdWords/SoapMessages.v201402.Designer.cs +++ b/tests/AdWords/SoapMessages.v201402.Designer.cs @@ -60,12 +60,6 @@ internal SoapMessages_v201402() { } } - /// - /// Looks up a localized string similar to <?xml version="1.0"?> - ///<Example> - /// <SOAP> - /// <Request>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Header&gt;&lt;RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201309"&gt;&lt;authToken xmlns="https://adwords.google.com/api/adwords/cm/v201309"&gt;******&lt;/authToken&gt;&lt;developerToken xmlns="https://adwo [rest of string was truncated]";. - /// internal static string GetAccountAlerts { get { return ResourceManager.GetString("GetAccountAlerts", resourceCulture); diff --git a/tests/AdWords/SoapMessages.v201406.Designer.cs b/tests/AdWords/SoapMessages.v201406.Designer.cs index cbea7b84503..918ff5e154b 100644 --- a/tests/AdWords/SoapMessages.v201406.Designer.cs +++ b/tests/AdWords/SoapMessages.v201406.Designer.cs @@ -60,12 +60,6 @@ internal SoapMessages_v201406() { } } - /// - /// Looks up a localized string similar to <?xml version="1.0"?> - ///<Example> - /// <SOAP> - /// <Request>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;&lt;soap:Header&gt;&lt;RequestHeader xmlns="https://adwords.google.com/api/adwords/mcm/v201406"&gt;&lt;authToken xmlns="https://adwords.google.com/api/adwords/cm/v201406"&gt;******&lt;/authToken&gt;&lt;developerToken xmlns="https://adwords [rest of string was truncated]";. - /// internal static string GetAccountAlerts { get { return ResourceManager.GetString("GetAccountAlerts", resourceCulture); diff --git a/tests/AdXBuyer/App.config b/tests/AdXBuyer/App.config index 1ee298baf62..a566c03c3c7 100644 --- a/tests/AdXBuyer/App.config +++ b/tests/AdXBuyer/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-adwords-dotnet/wiki/HowToUseAdWordsUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-adwords-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -55,10 +55,9 @@ run Common\Util\OAuth2TokenGenerator.cs to generate this section of the config file. --> - @@ -93,7 +92,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/adwords/api/docs/guides/service-accounts - and https://code.google.com/p/google-api-adwords-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. --> - - - - - - diff --git a/tests/AdXBuyer/ExampleTestsBase.cs b/tests/AdXBuyer/ExampleTestsBase.cs index 9978cbba6f8..64663473c81 100644 --- a/tests/AdXBuyer/ExampleTestsBase.cs +++ b/tests/AdXBuyer/ExampleTestsBase.cs @@ -37,13 +37,6 @@ public class ExampleTestsBase { /// protected AdWordsUser user = new AdWordsUser(); - /// - /// The interceptor for ClientLogin requests when running mocked code - /// examples. - /// - protected ClientLoginRequestInterceptor clientLoginInterceptor = - ClientLoginRequestInterceptor.Instance as ClientLoginRequestInterceptor; - /// /// The interceptor for AdWords API requests when running mocked code /// examples. @@ -74,24 +67,20 @@ protected void RunMockedExample(ExamplesMockData mockData, TestDelegate exampleD WebRequestInterceptor.OnBeforeSendResponse callback) { TextWriter oldWriter = Console.Out; try { - clientLoginInterceptor.Intercept = true; - clientLoginInterceptor.RaiseException = false; awapiInterceptor.Intercept = true; - AuthToken.Cache.Clear(); awapiInterceptor.LoadMessages(mockData.MockMessages, delegate(Uri requestUri, WebHeaderCollection headers, String body) { + VerifyHttpHeaders(headers); VerifySoapHeaders(requestUri, body); callback(requestUri, headers, body); } ); StringWriter newWriter = new StringWriter(); Console.SetOut(newWriter); - AdWordsAppConfig config = (user.Config as AdWordsAppConfig); exampleDelegate.Invoke(); Assert.AreEqual(newWriter.ToString().Trim(), mockData.ExpectedOutput.Trim()); } finally { Console.SetOut(oldWriter); - clientLoginInterceptor.Intercept = false; awapiInterceptor.Intercept = false; } } @@ -107,7 +96,6 @@ protected void RunExample(TestDelegate exampleDelegate) { Assert.DoesNotThrow(delegate() { TextWriter oldWriter = Console.Out; Console.SetOut(writer); - AuthToken.Cache.Clear(); exampleDelegate.Invoke(); Console.SetOut(oldWriter); Console.WriteLine(writer.ToString()); @@ -135,6 +123,23 @@ protected ExamplesMockData LoadMockData(string mockData) { InnerText); } + /// + /// Sets the mock OAuth2 tokens. + /// + protected void SetMockOAuth2Tokens() { + user.OAuthProvider.UpdatedOn = DateTime.Now; + user.OAuthProvider.ExpiresIn = int.Parse(OAuth2RequestInterceptor.EXPIRES_IN); + user.OAuthProvider.AccessToken = OAuth2RequestInterceptor.TEST_ACCESS_TOKEN; + } + + /// + /// Verifies the HTTP headers. + /// + /// The HTTP headers. + protected void VerifyHttpHeaders(WebHeaderCollection headers) { + Assert.AreEqual(headers["Authorization"], user.OAuthProvider.GetAuthHeader()); + } + /// /// Verifies the SOAP headers. /// @@ -155,10 +160,6 @@ protected void VerifySoapHeaders(Uri requestUri, string requestBody) { Assert.AreEqual(requestHeaders.Name, "RequestHeader"); foreach (XmlElement childNode in requestHeaders.ChildNodes) { switch (childNode.Name) { - case "authToken": - Assert.AreEqual(childNode.InnerText, "AUTH_TOKEN"); - break; - case "developerToken": Assert.AreEqual(childNode.InnerText, config.DeveloperToken); break; diff --git a/tests/AdXBuyer/Lib/AdWordsServiceFactoryTests.cs b/tests/AdXBuyer/Lib/AdWordsServiceFactoryTests.cs index 47669cd13a3..b10859f6fb4 100644 --- a/tests/AdXBuyer/Lib/AdWordsServiceFactoryTests.cs +++ b/tests/AdXBuyer/Lib/AdWordsServiceFactoryTests.cs @@ -28,8 +28,7 @@ namespace Google.Api.Ads.AdWords.Tests.Lib { /// [TestFixture] class AdWordsServiceFactoryTests { - private const string DEPRECATED_CLIENT_LOGIN_VERSION = "v201402"; - private const string SUPPORTED_CLIENT_LOGIN_VERSION = "v201309"; + private const string TEST_API_VERSION = "v201406"; private const string TEST_SERVICE = "MediaService"; private const string TEST_GROUP_NAME = "express"; @@ -51,62 +50,13 @@ public void Init() { } /// - /// Test that creating a service using ClientLogin in a deprecated version - /// throws an exception + /// Test creating a service using OAuth2. /// [Test] - [ExpectedException(typeof(AdWordsException))] - public void TestCreateServiceClientLoginDeprecated() { - ConfigureForClientLogin(); - serviceSignature = new AdWordsServiceSignature(DEPRECATED_CLIENT_LOGIN_VERSION, + public void TestCreateService() { + serviceSignature = new AdWordsServiceSignature(TEST_API_VERSION, TEST_SERVICE, TEST_GROUP_NAME); serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); } - - /// - /// Test that creating a service using ClientLogin in a supported version does not - /// throw an exception - /// - [Test] - public void TestCreateServiceClientLoginSupported() { - ConfigureForClientLogin(); - serviceSignature = new AdWordsServiceSignature(SUPPORTED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - /// - /// Test creating a service using OAuth2 in a version where ClientLogin is supported - /// - [Test] - public void TestCreateServiceOAuth2ClientLoginSupported() { - ConfigureForOAuth2(); - serviceSignature = new AdWordsServiceSignature(SUPPORTED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - /// - /// Test creating a service using OAuth2 in a version where ClientLogin is deprecated - /// - [Test] - public void TestCreateServiceOAuth2ClientLoginDeprecated() { - ConfigureForOAuth2(); - serviceSignature = new AdWordsServiceSignature(DEPRECATED_CLIENT_LOGIN_VERSION, - TEST_SERVICE, TEST_GROUP_NAME); - serviceFactory.CreateService(serviceSignature, new AdWordsUser(), testUri); - } - - private void ConfigureForOAuth2() { - AdWordsAppConfig config = new AdWordsAppConfig(); - config.AuthorizationMethod = AdWordsAuthorizationMethod.OAuth2; - serviceFactory.Config = config; - } - - private void ConfigureForClientLogin() { - AdWordsAppConfig config = new AdWordsAppConfig(); - config.AuthorizationMethod = AdWordsAuthorizationMethod.ClientLogin; - serviceFactory.Config = config; - } } } diff --git a/tests/AdXBuyer/Properties/Properties.cs b/tests/AdXBuyer/Properties/Properties.cs index 3f01f1a16a9..dda80e38782 100644 --- a/tests/AdXBuyer/Properties/Properties.cs +++ b/tests/AdXBuyer/Properties/Properties.cs @@ -20,5 +20,5 @@ [assembly: AssemblyProduct("AdWords API DotNet Client Library")] [assembly: AssemblyCopyright("Copyright 2011, Google Inc. All Rights Reserved.")] -[assembly: AssemblyVersion("18.1.0.0")] -[assembly: AssemblyFileVersion("18.1.0.0")] +[assembly: AssemblyVersion("18.2.0.0")] +[assembly: AssemblyFileVersion("18.2.0.0")] diff --git a/tests/Common/Mocks/MockTraceListener.cs b/tests/Common/Mocks/MockTraceListener.cs index 1fb86d96ae2..266c8957282 100644 --- a/tests/Common/Mocks/MockTraceListener.cs +++ b/tests/Common/Mocks/MockTraceListener.cs @@ -15,7 +15,9 @@ // Author: api.anash@gmail.com (Anash P. Oommen) using Google.Api.Ads.Common.Lib; + using System; +using System.Collections.Generic; namespace Google.Api.Ads.Common.Tests.Mocks { /// @@ -35,8 +37,9 @@ public MockTraceListener(AppConfig config) : base(config) { /// /// The list of fields to be masked. /// - protected override string[] GetFieldsToMask() { - return new string[] {"authToken", "developerToken"}; + protected override ISet GetFieldsToMask() { + return new HashSet(new string[] { "authToken", "developerToken" }, + StringComparer.OrdinalIgnoreCase); } /// diff --git a/tests/Dfa/App.config b/tests/Dfa/App.config index 3a6bc204c19..df933a64532 100644 --- a/tests/Dfa/App.config +++ b/tests/Dfa/App.config @@ -10,11 +10,11 @@ Web.config for quickly configuring and running a simple application. However, it is not mandatory to provide your settings in the config file, you may also set or override these settings at runtime. See - https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser + https://github.com/googleads/googleads-dotnet-lib/wiki/Getting-Started for details. You can refer to - https://code.google.com/p/google-api-dfa-dotnet/wiki/UnderstandingAppConfig + https://github.com/googleads/googleads-dotnet-lib/wiki/Understanding-App.config for detailed explanation of each configuration key. --> @@ -68,8 +68,8 @@ @@ -56,8 +56,8 @@ @@ -91,7 +91,7 @@ You should comment out all the keys for Web / Installed application OAuth flow above. See https://developers.google.com/doubleclick-publishers/docs/service_accounts - and https://code.google.com/p/google-api-dfp-dotnet/wiki/UsingOAuth + https://github.com/googleads/googleads-dotnet-lib/wiki/Using-OAuth2 for more details. -->