當前位置: 首頁>>代碼示例>>Python>>正文


Python views.oauth2_callback方法代碼示例

本文整理匯總了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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:31,代碼來源:test_views.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:31,代碼來源:test_views.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:9,代碼來源:test_views.py

示例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.') 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:13,代碼來源:test_views.py

示例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) 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:10,代碼來源:test_views.py

示例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.') 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:12,代碼來源:test_views.py

示例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.') 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:13,代碼來源:test_views.py


注:本文中的oauth2client.contrib.django_util.views.oauth2_callback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。