示例#1
0
 def sign(self, request):
     sign_request(None,
                  self.config['auth'],
                  headers=self.headers,
                  method=self.method.upper(),
                  params={'oauth_token': 'not-implemented'},
                  url=self.url)
示例#2
0
文件: views.py 项目: oremj/solitude
    def pre(self, request):
        config = settings.ZIPPY_CONFIGURATION.get(self.reference_name)
        if not config:
            raise ImproperlyConfigured('No config: %s' % self.reference_name)

        # Headers we want from the proxying request.
        self.headers = {
            'Content-Type': request.META.get('CONTENT_TYPE'),
            'Accept': request.META.get('HTTP_ACCEPT')
        }
        self.body = str(request.raw_post_data)
        self.method = request.META['REQUEST_METHOD'].lower()
        # The URL is made up of the defined scheme and host plus the trailing
        # URL after the proxy in urls.py.
        root = len(reverse('provider.proxy',
                   kwargs={'reference_name':self.reference_name}))

        self.url = url_join(config['url'], request.META['PATH_INFO'][root:])
        # Add in the query string.
        query = request.META.get('QUERY_STRING')
        if query:
            self.url = '%s?%s' % (self.url, query)
        # Before we do the request, use curling to sign the request headers.
        log.info('%s: %s' % (self.method.upper(), self.url))
        sign_request(None, config['auth'], headers=self.headers,
                     method=self.method.upper(),
                     params={'oauth_token': 'not-implemented'},
                     url=self.url)
示例#3
0
 def setup_authorization(self, keys):
     headers = {}
     sign_request(None,
                  method='GET',
                  extra=keys,
                  headers=headers,
                  url=settings.SITE_URL)
     return headers['Authorization']
 def test_signed_incorrectly(self):
     keys_ = keys_dict.copy()
     keys_['secret'] = 'baz'
     res = sign_request('GET', keys_, settings.SITE_URL, None)
     req = self.factory.get('/foo/', HTTP_AUTHORIZATION=res)
     with self.settings(REQUIRE_OAUTH=True):
         ok_(not self.authentication.is_authenticated(req))
         eq_(req.OAUTH_KEY, None)
示例#5
0
def reference(request, reference_name):
    """
    Pass through the request to the reference implementation.
    We have to:
    * get the provider from the URL
    * sign the request with OAuth
    """
    if reference_name not in settings.ZIPPY_CONFIGURATION:
        raise ValueError('Unknown provider: {}'.format(reference_name))

    new_request = prepare(request)
    new_request['url'] = reference_url(request, new_request, reference_name)

    sign_request(None,
                 settings.ZIPPY_CONFIGURATION[reference_name]['auth'],
                 headers=new_request['headers'],
                 method=new_request['method'].upper(),
                 params={'oauth_token': 'not-implemented'},
                 url=new_request['url'])
    return send(new_request)
示例#6
0
def reference(request, reference_name):
    """
    Pass through the request to the reference implementation.
    We have to:
    * get the provider from the URL
    * sign the request with OAuth
    """
    if reference_name not in settings.ZIPPY_CONFIGURATION:
        raise ValueError('Unknown provider: {}'.format(reference_name))

    new_request = prepare(request)
    new_request['url'] = reference_url(request, new_request, reference_name)

    sign_request(
        None,
        settings.ZIPPY_CONFIGURATION[reference_name]['auth'],
        headers=new_request['headers'],
        method=new_request['method'].upper(),
        params={'oauth_token': 'not-implemented'},
        url=new_request['url'])
    return send(new_request)
示例#7
0
 def sign(self, request):
     sign_request(None, self.config['auth'], headers=self.headers,
                  method=self.method.upper(),
                  params={'oauth_token': 'not-implemented'},
                  url=self.url)
 def test_signed(self):
     res = sign_request('GET', keys_dict, settings.SITE_URL, None)
     req = self.factory.get('/', HTTP_AUTHORIZATION=res)
     with self.settings(REQUIRE_OAUTH=True):
         ok_(self.authentication.is_authenticated(req))
         eq_(req.OAUTH_KEY, 'foo')
 def setup_authorization(self, keys):
     headers = {}
     sign_request(None, method="GET", extra=keys, headers=headers, url=settings.SITE_URL)
     return headers["Authorization"]