Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
https://github.com/google/oauth2client/issues/443
Browse files Browse the repository at this point in the history
Allow for binary code values in oauth_flow.step2_exchange(code). An issue with Python 3 since the code will be binary.
A simple test that binary values are allowed. credentials = self.flow.step2_exchange(b'some random code', http=http)

tox -e py34  -- tests.test_client:OAuth2WebServerFlowTest.test_exchange_success_binary_code
  • Loading branch information
happyspace committed Feb 29, 2016
1 parent 4b0a5ed commit 8d07159
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion oauth2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,7 +2069,7 @@ def step2_exchange(self, code=None, http=None, device_flow_info=None):

if code is None:
code = device_flow_info.device_code
elif not isinstance(code, six.string_types):
elif not isinstance(code, (six.string_types, six.binary_type)):
if 'code' not in code:
raise FlowExchangeError(code.get(
'error', 'No code was supplied in the query parameters.'))
Expand Down
15 changes: 15 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,21 @@ def test_exchange_success(self):
self.assertEqual('dummy_revoke_uri', credentials.revoke_uri)
self.assertEqual(set(['foo']), credentials.scopes)

def test_exchange_success_binary_code(self):
payload = (b'{'
b' "access_token":"SlAV32hkKG",'
b' "expires_in":3600,'
b' "refresh_token":"8xLOxBtZp8"'
b'}')

http = HttpMockSequence([({'status': '200'}, payload)])
credentials = self.flow.step2_exchange(b'some random code', http=http)
self.assertEqual('SlAV32hkKG', credentials.access_token)
self.assertNotEqual(None, credentials.token_expiry)
self.assertEqual('8xLOxBtZp8', credentials.refresh_token)
self.assertEqual('dummy_revoke_uri', credentials.revoke_uri)
self.assertEqual(set(['foo']), credentials.scopes)

def test_exchange_dictlike(self):
class FakeDict(object):
def __init__(self, d):
Expand Down

0 comments on commit 8d07159

Please sign in to comment.