oob -> urn:ietf:wg:oauth:2.0:00b.

Reviewed in http://codereview.appspot.com/5647045/.
This commit is contained in:
Joe Gregorio
2012-02-09 12:18:44 -05:00
parent 8e000ed390
commit f2326c0524
3 changed files with 15 additions and 10 deletions

View File

@@ -55,6 +55,9 @@ EXPIRY_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
# Which certs to use to validate id_tokens received. # Which certs to use to validate id_tokens received.
ID_TOKEN_VERIFICATON_CERTS = 'https://www.googleapis.com/oauth2/v1/certs' ID_TOKEN_VERIFICATON_CERTS = 'https://www.googleapis.com/oauth2/v1/certs'
# Constant to use for the out of band OAuth 2.0 flow.
OOB_CALLBACK_URN = 'urn:ietf:wg:oauth:2.0:oob'
class Error(Exception): class Error(Exception):
"""Base error for this module.""" """Base error for this module."""
@@ -843,15 +846,15 @@ class OAuth2WebServerFlow(Flow):
self.params.update(kwargs) self.params.update(kwargs)
self.redirect_uri = None self.redirect_uri = None
def step1_get_authorize_url(self, redirect_uri='oob'): def step1_get_authorize_url(self, redirect_uri=OOB_CALLBACK_URN):
"""Returns a URI to redirect to the provider. """Returns a URI to redirect to the provider.
Args: Args:
redirect_uri: string, Either the string 'oob' for a non-web-based redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob' for
application, or a URI that handles the callback from a non-web-based application, or a URI that handles the callback from
the authorization server. the authorization server.
If redirect_uri is 'oob' then pass in the If redirect_uri is 'urn:ietf:wg:oauth:2.0:oob' then pass in the
generated verification code to step2_exchange, generated verification code to step2_exchange,
otherwise pass in the query parameters received otherwise pass in the query parameters received
at the callback uri to step2_exchange. at the callback uri to step2_exchange.

View File

@@ -30,6 +30,7 @@ import sys
import webbrowser import webbrowser
from client import FlowExchangeError from client import FlowExchangeError
from client import OOB_CALLBACK_URN
try: try:
from urlparse import parse_qsl from urlparse import parse_qsl
@@ -120,7 +121,7 @@ def run(flow, storage, http=None):
if FLAGS.auth_local_webserver: if FLAGS.auth_local_webserver:
oauth_callback = 'http://%s:%s/' % (FLAGS.auth_host_name, port_number) oauth_callback = 'http://%s:%s/' % (FLAGS.auth_host_name, port_number)
else: else:
oauth_callback = 'oob' oauth_callback = OOB_CALLBACK_URN
authorize_url = flow.step1_get_authorize_url(oauth_callback) authorize_url = flow.step1_get_authorize_url(oauth_callback)
if FLAGS.auth_local_webserver: if FLAGS.auth_local_webserver:

View File

@@ -42,6 +42,7 @@ from oauth2client.client import AssertionCredentials
from oauth2client.client import FlowExchangeError from oauth2client.client import FlowExchangeError
from oauth2client.client import OAuth2Credentials from oauth2client.client import OAuth2Credentials
from oauth2client.client import OAuth2WebServerFlow from oauth2client.client import OAuth2WebServerFlow
from oauth2client.client import OOB_CALLBACK_URN
from oauth2client.client import VerifyJwtTokenError from oauth2client.client import VerifyJwtTokenError
from oauth2client.client import _extract_id_token from oauth2client.client import _extract_id_token
@@ -196,14 +197,14 @@ class OAuth2WebServerFlowTest(unittest.TestCase):
) )
def test_construct_authorize_url(self): def test_construct_authorize_url(self):
authorize_url = self.flow.step1_get_authorize_url('oob') authorize_url = self.flow.step1_get_authorize_url('OOB_CALLBACK_URN')
parsed = urlparse.urlparse(authorize_url) parsed = urlparse.urlparse(authorize_url)
q = parse_qs(parsed[4]) q = parse_qs(parsed[4])
self.assertEqual(q['client_id'][0], 'client_id+1') self.assertEqual(q['client_id'][0], 'client_id+1')
self.assertEqual(q['response_type'][0], 'code') self.assertEqual(q['response_type'][0], 'code')
self.assertEqual(q['scope'][0], 'foo') self.assertEqual(q['scope'][0], 'foo')
self.assertEqual(q['redirect_uri'][0], 'oob') self.assertEqual(q['redirect_uri'][0], 'OOB_CALLBACK_URN')
self.assertEqual(q['access_type'][0], 'offline') self.assertEqual(q['access_type'][0], 'offline')
def test_override_flow_access_type(self): def test_override_flow_access_type(self):
@@ -215,14 +216,14 @@ class OAuth2WebServerFlowTest(unittest.TestCase):
user_agent='unittest-sample/1.0', user_agent='unittest-sample/1.0',
access_type='online' access_type='online'
) )
authorize_url = flow.step1_get_authorize_url('oob') authorize_url = flow.step1_get_authorize_url('OOB_CALLBACK_URN')
parsed = urlparse.urlparse(authorize_url) parsed = urlparse.urlparse(authorize_url)
q = parse_qs(parsed[4]) q = parse_qs(parsed[4])
self.assertEqual(q['client_id'][0], 'client_id+1') self.assertEqual(q['client_id'][0], 'client_id+1')
self.assertEqual(q['response_type'][0], 'code') self.assertEqual(q['response_type'][0], 'code')
self.assertEqual(q['scope'][0], 'foo') self.assertEqual(q['scope'][0], 'foo')
self.assertEqual(q['redirect_uri'][0], 'oob') self.assertEqual(q['redirect_uri'][0], 'OOB_CALLBACK_URN')
self.assertEqual(q['access_type'][0], 'online') self.assertEqual(q['access_type'][0], 'online')
def test_exchange_failure(self): def test_exchange_failure(self):