Add default for OAuth 2.0 parameter access_type of offline.

Reviewed in http://codereview.appspot.com/5316073/.
This commit is contained in:
Joe Gregorio
2011-11-03 10:47:32 -04:00
parent 1a4a2d3f7e
commit 69a0aca251
2 changed files with 24 additions and 1 deletions

View File

@@ -641,7 +641,10 @@ class OAuth2WebServerFlow(Flow):
self.user_agent = user_agent
self.auth_uri = auth_uri
self.token_uri = token_uri
self.params = kwargs
self.params = {
'access_type': 'offline',
}
self.params.update(kwargs)
self.redirect_uri = None
def step1_get_authorize_url(self, redirect_uri='oob'):

View File

@@ -191,6 +191,26 @@ class OAuth2WebServerFlowTest(unittest.TestCase):
self.assertEqual(q['response_type'][0], 'code')
self.assertEqual(q['scope'][0], 'foo')
self.assertEqual(q['redirect_uri'][0], 'oob')
self.assertEqual(q['access_type'][0], 'offline')
def test_override_flow_access_type(self):
"""Passing access_type overrides the default."""
flow = OAuth2WebServerFlow(
client_id='client_id+1',
client_secret='secret+1',
scope='foo',
user_agent='unittest-sample/1.0',
access_type='online'
)
authorize_url = flow.step1_get_authorize_url('oob')
parsed = urlparse.urlparse(authorize_url)
q = parse_qs(parsed[4])
self.assertEqual(q['client_id'][0], 'client_id+1')
self.assertEqual(q['response_type'][0], 'code')
self.assertEqual(q['scope'][0], 'foo')
self.assertEqual(q['redirect_uri'][0], 'oob')
self.assertEqual(q['access_type'][0], 'online')
def test_exchange_failure(self):
http = HttpMockSequence([