Example #1
0
    def test_oauth2_step1(self):
        with patch('uuid.uuid4') as fake:
            fake.return_value = 'random-string'

            request = DummyRequest()
            request.params = {'next_url': 'http://localhost/'}
            request.session = {}
            response = oauth2_step1(
                request=request,
                auth_uri='http://example.com/oauth2/auth',
                client_id='1234',
                redirect_url='http://localhost/oauth2/callback',
                scope='scope1 scope2')
            self.assertEqual(response.status, '302 Found')
            url = urlparse.urlparse(response.location)
            self.assertEqual(url.netloc, 'example.com')
            self.assertEqual(url.path, '/oauth2/auth')
            query = urlparse.parse_qs(url.query)
            self.assertEqual(
                query, {
                    'scope': ['scope1 scope2'],
                    'state': ['random-string'],
                    'redirect_uri': ['http://localhost/oauth2/callback'],
                    'response_type': ['code'],
                    'client_id': ['1234'],
                })
            self.assertEqual(request.session['next_url'], 'http://localhost/')
    def test_oauth2_step1(self):
        with patch('uuid.uuid4') as fake:
            fake.return_value = 'random-string'

            request = DummyRequest()
            request.params = {'next_url': 'http://localhost/'}
            request.session = {}
            response = oauth2_step1(
                request=request,
                auth_uri='http://example.com/oauth2/auth',
                client_id='1234',
                redirect_url='http://localhost/oauth2/callback',
                scope='scope1 scope2'
                )
            self.assertEqual(response.status, '302 Found')
            url = urlparse.urlparse(response.location)
            self.assertEqual(url.netloc, 'example.com')
            self.assertEqual(url.path, '/oauth2/auth')
            query = urlparse.parse_qs(url.query)
            self.assertEqual(query, {
                    'scope': ['scope1 scope2'],
                    'state': ['random-string'],
                    'redirect_uri': ['http://localhost/oauth2/callback'],
                    'response_type': ['code'],
                    'client_id': ['1234'],
                    })
            self.assertEqual(request.session['next_url'], 'http://localhost/')
Example #3
0
def facebook_login(request):
    settings = request.registry.settings
    return oauth2_step1(
        request=request,
        auth_uri=settings['facebook_dialog_oauth_url'],
        client_id=settings['facebook_app_id'],
        redirect_url=request.route_url('facebook_callback'),
        scope=_get_scope(),
        )
Example #4
0
def google_login(request):
    settings = request.registry.settings
    return oauth2_step1(
        request=request,
        auth_uri=settings['google_auth_uri'],
        client_id=settings['google_client_id'],
        redirect_url=request.route_url('google_callback'),
        scope=_get_scope(),
        )