Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 068eb35

Browse files
author
Jon Wayne Parrott
authored
Don't invoke application default credentials logic when developerKey is provided (#347)
1 parent 12751ca commit 068eb35

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

‎googleapiclient/discovery.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ def build_from_document(
355355
scopes = list(
356356
service.get('auth', {}).get('oauth2', {}).get('scopes', {}).keys())
357357

358-
# If so, then the we need to setup authentication.
359-
if scopes:
358+
# If so, then the we need to setup authentication if no developerKey is
359+
# specified.
360+
if scopes and not developerKey:
360361
# If the user didn't pass in credentials, attempt to acquire application
361362
# default credentials.
362363
if credentials is None:

‎tests/test_discovery.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,16 @@ def test_building_with_explicit_http(self):
437437
discovery, base="https://www.googleapis.com/", http=http)
438438
self.assertEquals(plus._http, http)
439439

440+
def test_building_with_developer_key_skips_adc(self):
441+
discovery = open(datafile('plus.json')).read()
442+
plus = build_from_document(
443+
discovery, base="https://www.googleapis.com/", developerKey='123')
444+
self.assertIsInstance(plus._http, httplib2.Http)
445+
# It should not be an AuthorizedHttp, because that would indicate that
446+
# application default credentials were used.
447+
self.assertNotIsInstance(plus._http, google_auth_httplib2.AuthorizedHttp)
448+
449+
440450
class DiscoveryFromHttp(unittest.TestCase):
441451
def setUp(self):
442452
self.old_environ = os.environ.copy()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /