Repository: google/google-api-python-client (python)

Issue:
Change from 1.5.5 to 1.6.2 results in authentication failure.
We have some code that successfully talks to a Google API using v1.5.5 but breaks under v1.6.2 with the following error:

   "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential"

Our build statement looks like:

     return build(
         'monitoring',
         'v3',
         discoveryServiceUrl=discovery_url,
         developerKey=self.api_key,
         credentials=credentials)

I'm wondering if the following commit may be culprit here:

    https://github.com/google/google-api-python-client/commit/068eb35c9a70e31a42f04d5cb69c36d59e4a2a69

Because we supply both "credentials" and "developerKey" and expect the bearer token / other context from the credentials to be propagated regardless of the presence of "developerKey" (it was my understanding that "developerKey" simply adds a "key=<api-key>" to the discovery URL and to the API requests, but the headers implied by the credentials should still be provided in this case). 

Can you fix this? Thanks!

Pull request description:
Raise ValueError if credentials and developerKey are both specified
Fixes #357

Patch:
diff --git a/googleapiclient/discovery.py b/googleapiclient/discovery.py
index fe19022c9..c8956f43f 100644
--- a/googleapiclient/discovery.py
+++ b/googleapiclient/discovery.py
@@ -334,6 +334,10 @@ def build_from_document(
   if http is not None and credentials is not None:
     raise ValueError('Arguments http and credentials are mutually exclusive.')
 
+  if developerKey is not None and credentials is not None:
+    raise ValueError(
+      'Arguments developerKey and credentials are mutually exclusive.')
+
   if isinstance(service, six.string_types):
     service = json.loads(service)
 


Test patch:
diff --git a/tests/test_discovery.py b/tests/test_discovery.py
index 89b0dd782..8818f4a30 100644
--- a/tests/test_discovery.py
+++ b/tests/test_discovery.py
@@ -375,6 +375,13 @@ class DiscoveryErrors(unittest.TestCase):
       build(
         'plus', 'v1', http=http, credentials=mock.sentinel.credentials)
 
+  def test_credentials_and_developer_key_mutually_exclusive(self):
+    http = HttpMock(datafile('plus.json'), {'status': '200'})
+    with self.assertRaises(ValueError):
+      build(
+        'plus', 'v1', credentials=mock.sentinel.credentials,
+        developerKey=mock.sentinel.credentials)
+
 
 class DiscoveryFromDocument(unittest.TestCase):
   MOCK_CREDENTIALS = mock.Mock(spec=google.auth.credentials.Credentials)