Allow setting the response_type in OAuth2WebServerFlow.

Reviewed in https://codereview.appspot.com/6749066/.
Fixes issue #201.
This commit is contained in:
Joe Gregorio
2012-10-23 16:13:44 -04:00
parent 81fde8e0f1
commit 32f7319a5e
2 changed files with 10 additions and 5 deletions

View File

@@ -1017,6 +1017,10 @@ class OAuth2WebServerFlow(Flow):
**kwargs):
"""Constructor for OAuth2WebServerFlow.
The kwargs argument is used to set extra query parameters on the
auth_uri. For example, the access_type and approval_prompt
query parameters can be set via kwargs.
Args:
client_id: string, client identifier.
client_secret: string client secret.
@@ -1044,6 +1048,7 @@ class OAuth2WebServerFlow(Flow):
self.token_uri = token_uri
self.params = {
'access_type': 'offline',
'response_type': 'code',
}
self.params.update(kwargs)
@@ -1070,7 +1075,6 @@ class OAuth2WebServerFlow(Flow):
raise ValueError('The value of redirect_uri must not be None.')
query = {
'response_type': 'code',
'client_id': self.client_id,
'redirect_uri': self.redirect_uri,
'scope': self.scope,

View File

@@ -256,22 +256,23 @@ class OAuth2WebServerFlowTest(unittest.TestCase):
self.assertEqual(OOB_CALLBACK_URN, q['redirect_uri'][0])
self.assertEqual('offline', q['access_type'][0])
def test_override_flow_access_type(self):
"""Passing access_type overrides the default."""
def test_override_flow_via_kwargs(self):
"""Passing kwargs to override defaults."""
flow = OAuth2WebServerFlow(
client_id='client_id+1',
client_secret='secret+1',
scope='foo',
redirect_uri=OOB_CALLBACK_URN,
user_agent='unittest-sample/1.0',
access_type='online'
access_type='online',
response_type='token'
)
authorize_url = flow.step1_get_authorize_url()
parsed = urlparse.urlparse(authorize_url)
q = parse_qs(parsed[4])
self.assertEqual('client_id+1', q['client_id'][0])
self.assertEqual('code', q['response_type'][0])
self.assertEqual('token', q['response_type'][0])
self.assertEqual('foo', q['scope'][0])
self.assertEqual(OOB_CALLBACK_URN, q['redirect_uri'][0])
self.assertEqual('online', q['access_type'][0])