本文整理汇总了Python中oauth2client.contrib.django_util.views.oauth2_callback方法的典型用法代码示例。如果您正苦于以下问题:Python views.oauth2_callback方法的具体用法?Python views.oauth2_callback怎么用?Python views.oauth2_callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.contrib.django_util.views
的用法示例。
在下文中一共展示了views.oauth2_callback方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_callback_works
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_callback_works(self, jsonpickle_mock):
request = self.factory.get('oauth2/oauth2callback', data={
'state': json.dumps(self.fake_state),
'code': 123
})
self.session['google_oauth2_csrf_token'] = self.CSRF_TOKEN
flow = client.OAuth2WebServerFlow(
client_id='clientid',
client_secret='clientsecret',
scope=['email'],
state=json.dumps(self.fake_state),
redirect_uri=request.build_absolute_uri("oauth2/oauth2callback"))
name = 'google_oauth2_flow_{0}'.format(self.CSRF_TOKEN)
pickled_flow = object()
self.session[name] = pickled_flow
flow.step2_exchange = mock.Mock()
jsonpickle_mock.decode.return_value = flow
request.session = self.session
request.user = self.user
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseRedirect)
self.assertEqual(
response.status_code, django.http.HttpResponseRedirect.status_code)
self.assertEqual(response['Location'], self.RETURN_URL)
jsonpickle_mock.decode.assert_called_once_with(pickled_flow)
示例2: test_callback_handles_bad_flow_exchange
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_callback_handles_bad_flow_exchange(self, jsonpickle_mock):
request = self.factory.get('oauth2/oauth2callback', data={
"state": json.dumps(self.fake_state),
"code": 123
})
self.session['google_oauth2_csrf_token'] = self.CSRF_TOKEN
flow = client.OAuth2WebServerFlow(
client_id='clientid',
client_secret='clientsecret',
scope=['email'],
state=json.dumps(self.fake_state),
redirect_uri=request.build_absolute_uri('oauth2/oauth2callback'))
session_key = 'google_oauth2_flow_{0}'.format(self.CSRF_TOKEN)
pickled_flow = object()
self.session[session_key] = pickled_flow
def local_throws(code):
raise client.FlowExchangeError('test')
flow.step2_exchange = local_throws
jsonpickle_mock.decode.return_value = flow
request.session = self.session
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
jsonpickle_mock.decode.assert_called_once_with(pickled_flow)
示例3: test_error_returns_bad_request
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_error_returns_bad_request(self):
request = self.factory.get('oauth2/oauth2callback', data={
'error': 'There was an error in your authorization.',
})
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
self.assertIn(b'Authorization failed', response.content)
示例4: test_no_session
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_no_session(self):
request = self.factory.get('oauth2/oauth2callback', data={
'code': 123,
'state': json.dumps(self.fake_state)
})
request.session = self.session
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
self.assertEqual(
response.content, b'No existing session for this flow.')
示例5: test_missing_state_returns_bad_request
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_missing_state_returns_bad_request(self):
request = self.factory.get('oauth2/oauth2callback', data={
'code': 123
})
self.session['google_oauth2_csrf_token'] = "token"
request.session = self.session
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
示例6: test_bad_csrf
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_bad_csrf(self):
request = self.factory.get('oauth2/oauth2callback', data={
"state": json.dumps(self.fake_state),
"code": 123
})
self.session['google_oauth2_csrf_token'] = 'WRONG TOKEN'
request.session = self.session
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
self.assertEqual(response.content, b'Invalid CSRF token.')
示例7: test_no_saved_flow
# 需要导入模块: from oauth2client.contrib.django_util import views [as 别名]
# 或者: from oauth2client.contrib.django_util.views import oauth2_callback [as 别名]
def test_no_saved_flow(self):
request = self.factory.get('oauth2/oauth2callback', data={
'state': json.dumps(self.fake_state),
'code': 123
})
self.session['google_oauth2_csrf_token'] = self.CSRF_TOKEN
self.session['google_oauth2_flow_{0}'.format(self.CSRF_TOKEN)] = None
request.session = self.session
response = views.oauth2_callback(request)
self.assertIsInstance(response, http.HttpResponseBadRequest)
self.assertEqual(response.content, b'Missing Oauth2 flow.')