Example #1
0
    def test_get_authorization_url_exception(self, oauth2_mock):
        session_mock = oauth2_mock.return_value

        session_mock.authorization_url = mock.Mock(side_effect=Exception)

        with self.assertRaises(oauth2.OAuth2Error):
            oauth2.get_authorization_url('http://test.com/authorization',
                                         'http://test.com/certification')
Example #2
0
def login_oauth2(request):
    try:
        common.authentication_required(request)

        logger.info('Authenticating OAuth2 for {}'.format(
            request.user.auth.openid_url))

        auth_service, cert_service = openid.services(
            request.user.auth.openid_url, (URN_AUTHORIZE, URN_RESOURCE))

        redirect_url, state = oauth2.get_authorization_url(
            auth_service.server_url, cert_service.server_url)

        logger.info('Retrieved authorization url for OpenID {}'.format(
            request.user.auth.openid_url))

        request.session.update({
            'oauth_state': state,
            'openid': request.user.auth.openid_url
        })
    except WPSError as e:
        logger.exception('Error authenticating OAuth2')

        return common.failed(str(e))
    else:
        return common.success({'redirect': redirect_url})
Example #3
0
    def test_get_authorization_url(self, oauth2_mock):
        session_mock = oauth2_mock.return_value

        session_mock.authorization_url = mock.Mock(
            return_value='http://test.com/authorization')

        result = oauth2.get_authorization_url('http://test.com/authorization',
                                              'http://test.com/certification')

        self.assertEqual(result, 'http://test.com/authorization')