diff --git a/google_ads_config.rb b/google_ads_config.rb index 50c6f7ab2..2aa531236 100644 --- a/google_ads_config.rb +++ b/google_ads_config.rb @@ -26,6 +26,12 @@ c.client_secret = 'INSERT_CLIENT_SECRET_HERE' c.refresh_token = 'INSERT_REFRESH_TOKEN_HERE' + # Whether to use the Google Cloud Organization of your Google Cloud + # project instead of developer token to determine your Google Ads API access levels. + # Use this flag only if you are enrolled into a limited pilot that supports + # this configuration. + # c.use_cloud_org_for_api_access = false + # You can also authenticate using a service account. If "keyfile" is # specified below, then service account authentication will be assumed and # the above authentication fields ignored. Read more about service account diff --git a/lib/google/ads/google_ads/config.rb b/lib/google/ads/google_ads/config.rb index c78024a2d..366861204 100644 --- a/lib/google/ads/google_ads/config.rb +++ b/lib/google/ads/google_ads/config.rb @@ -32,6 +32,7 @@ class Config attr_accessor :developer_token attr_accessor :login_customer_id attr_accessor :linked_customer_id + attr_accessor :use_cloud_org_for_api_access attr_accessor :log_level attr_accessor :log_target @@ -55,6 +56,7 @@ def initialize(&block) @developer_token = nil @login_customer_id = nil @linked_customer_id = nil + @use_cloud_org_for_api_access = false @log_level = nil @log_target = nil diff --git a/lib/google/ads/google_ads/google_ads_client.rb b/lib/google/ads/google_ads/google_ads_client.rb index 6c94a9f65..1e4b5b6d6 100644 --- a/lib/google/ads/google_ads/google_ads_client.rb +++ b/lib/google/ads/google_ads/google_ads_client.rb @@ -103,6 +103,7 @@ def load_environment_config @config.developer_token = ENV.fetch("GOOGLE_ADS_DEVELOPER_TOKEN", @config.developer_token) @config.login_customer_id = ENV.fetch("GOOGLE_ADS_LOGIN_CUSTOMER_ID", @config.login_customer_id) @config.linked_customer_id = ENV.fetch("GOOGLE_ADS_LINKED_CUSTOMER_ID", @config.linked_customer_id) + @config.use_cloud_org_for_api_access = ENV.fetch("GOOGLE_ADS_USE_CLOUD_ORG_FOR_API_ACCESS", @config.use_cloud_org_for_api_access) @config.api_endpoint = ENV.fetch("GOOGLE_ADS_ENDPOINT", @config.api_endpoint) # Client library-specific variables diff --git a/lib/google/ads/google_ads/service_lookup.rb b/lib/google/ads/google_ads/service_lookup.rb index 85829a909..095d703f0 100644 --- a/lib/google/ads/google_ads/service_lookup.rb +++ b/lib/google/ads/google_ads/service_lookup.rb @@ -62,9 +62,13 @@ def gax_service_params end def headers - headers = { - :"developer-token" => config.developer_token - } + headers = {} + + # If config.use_cloud_org_for_api_access is not True, add the developer + # token to the request's metadata + if !config.use_cloud_org_for_api_access + headers[:"developer-token"] = config.developer_token + end if config.login_customer_id validate_customer_id(:login_customer_id) diff --git a/test/test_config.rb b/test/test_config.rb index eebc7df64..f8dd28c21 100644 --- a/test/test_config.rb +++ b/test/test_config.rb @@ -61,4 +61,26 @@ def test_configure() assert_equal(client_secret_value, config.client_secret) assert_equal(developer_token_value, config.developer_token) end + + def test_use_cloud_org_for_api_access() + config = Google::Ads::GoogleAds::Config.new + + refresh_token_value = '1234' + client_id_value = 'abcd' + client_secret_value = '!@#$' + use_cloud_org_for_api_access = true + + config.configure do |c| + c.refresh_token = refresh_token_value + c.client_id = client_id_value + c.client_secret = client_secret_value + c.use_cloud_org_for_api_access = true + end + + assert_equal(refresh_token_value, config.refresh_token) + assert_equal(client_id_value, config.client_id) + assert_equal(client_secret_value, config.client_secret) + assert_equal(nil, config.developer_token) + assert_equal(true, config.use_cloud_org_for_api_access) + end end