当前位置: 首页>>代码示例>>Python>>正文


Python OAuthRequest.from_consumer_and_token方法代码示例

本文整理汇总了Python中oauth.oauth.OAuthRequest.from_consumer_and_token方法的典型用法代码示例。如果您正苦于以下问题:Python OAuthRequest.from_consumer_and_token方法的具体用法?Python OAuthRequest.from_consumer_and_token怎么用?Python OAuthRequest.from_consumer_and_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth.oauth.OAuthRequest的用法示例。


在下文中一共展示了OAuthRequest.from_consumer_and_token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: auth

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
def auth(request, site):
	creds = OAUTH_CREDENTIALS.get(site.upper())
	if not creds:
		raise Http404('Site %s not found' % site)
	
	urls = creds.get('URLS', {})
	
	if 'DIALOG' in urls:
		request.session['preauth_url'] = request.META.get('HTTP_REFERER')
		return HttpResponseRedirect(urls['DIALOG'])
	
	ssl = creds.get('SSL', False)
	server = creds.get('SERVER', '%s.com' % site.lower())
	klass = ssl and HTTPSConnection or HTTPConnection
	
	request.session['preauth_url'] = request.META.get('HTTP_REFERER')
	
	consumer = OAuthConsumer(
		str(creds['CONSUMER_KEY']),
		str(creds['CONSUMER_SECRET'])
	)
	
	oauth_request = OAuthRequest.from_consumer_and_token(
		consumer, http_url = urls.get('REQUEST_TOKEN')
	)
	
	oauth_request.sign_request(SIGNATURE_METHOD(), consumer, None)
	url = oauth_request.to_url()
	
	connection = klass(server)
	connection.request(oauth_request.http_method, url)
	response = connection.getresponse()
	resp = response.read()
	
	token = OAuthToken.from_string(resp)
	request.session['unauth_token'] = token
	
	auth_url = urls.get('AUTHORISATION')
	if isinstance(auth_url, (list, tuple)):
		params = auth_url[1]
		auth_url = auth_url[0]
	else:
		params = {}
	
	oauth_request = OAuthRequest.from_consumer_and_token(
		consumer, token = token,
		http_url = auth_url, parameters = params
	)
	
	oauth_request.sign_request(SIGNATURE_METHOD(), consumer, token)
	return HttpResponseRedirect(
		oauth_request.to_url()
	)
开发者ID:iamsteadman,项目名称:meegloo,代码行数:55,代码来源:views.py

示例2: getTwitterOAuthURL

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
def getTwitterOAuthURL(conf, oauthTokenDict):
    """
    Obtain a URL from twitter.com that we can redirect a user to so they
    can authenticate themselves and authorize loveme.do to act on their
    behalf.

    @param conf: the lovemedo configuration.
    @param oauthTokenDict: A C{dict} mapping token keys to tokens.
    @return: A C{Deferred} that fires with the URL for OAuth verification.
    """
    log.msg('Got login URL request.')

    def _makeURL(result):
        token = OAuthToken.from_string(result)
        # Store the token by key so we can find it when the callback comes.
        oauthTokenDict[token.key] = token
        request = OAuthRequest.from_token_and_callback(
            token=token, http_url=conf.authorization_url)
        url = request.to_url()
        log.msg('Browser OAuth redirect URL = %r' % url)
        return url

    consumer = OAuthConsumer(conf.consumer_key, conf.consumer_secret)
    request = OAuthRequest.from_consumer_and_token(
        consumer, callback=conf.callback_url,
        http_url=conf.request_token_url)
    request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
    r = RetryingCall(
        client.getPage, conf.request_token_url, headers=request.to_header())
    d = r.start()
    d.addCallback(_makeURL)
    d.addErrback(log.err)
    return d
开发者ID:ceronman,项目名称:lastpage-server,代码行数:35,代码来源:twitter.py

示例3: fetch_access_token

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def fetch_access_token(self,
                           unauth_request_token_key,
                           unauth_request_token_secret,
                           oauth_verifier):
        """ After the user has authorizated API access via the authorization
        URL, get the (semi-)permanent access key using the user-authorized
        request token.

        Keyword arguments:
        unauth_request_token -- the user-authorized OAuth request token
        oauth_verifier -- per OAuth 1.0 Revision A

        """
        url = "%s?oauth_verifier=%s" % (YAMMER_ACCESS_TOKEN_URL,
                                        oauth_verifier)
        try:
            unauth_request_token = OAuthToken(unauth_request_token_key,
                                              unauth_request_token_secret)
            oauth_request = OAuthRequest.from_consumer_and_token(
                                                self._consumer,
                                                token=unauth_request_token,
                                                http_method='POST',
                                                http_url=url)
            oauth_request.sign_request(self._signature,
                                       self._consumer,
                                       unauth_request_token)
            headers = oauth_request.to_header()
        except OAuthError, m:
            raise YammerError(m.message)
开发者ID:jaivikram,项目名称:python-yammer-oauth,代码行数:31,代码来源:yammer.py

示例4: _fetch_resource

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def _fetch_resource(self, url, parameters=None, method = 'GET'):
        """ Retrieve a Yammer API resource.

        Keyword arguments:
        url -- a Yammer API URL (excluding query parameters)
        parameters -- used to pass query parameters to add to the request
                      (optional).

        """
        if not self._access_token:
            raise YammerError("Can't fetch resource. Missing access token!")

        try:
            oauth_request = OAuthRequest.from_consumer_and_token(
                                                self._consumer,
                                                token=self._access_token,
                                                http_method=method,
                                                http_url=url,
                                                parameters=parameters)
            headers = oauth_request.to_header()
            oauth_request.sign_request(self._signature,
                                       self._consumer,
                                       self._access_token)
            url = oauth_request.to_url()
        except OAuthError, m:
            raise YammerError(m.message)
开发者ID:jaivikram,项目名称:python-yammer-oauth,代码行数:28,代码来源:yammer.py

示例5: get_request

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def get_request(self, headers=None, **kwargs):
        request = super(Flixject, self).get_request(headers=headers, **kwargs)
        method = request.get('method', 'GET')

        # Apply OAuthness.
        csr = OAuthConsumer(*self.api_token)
        orq = OAuthRequest.from_consumer_and_token(csr, http_method=method,
            http_url=request['uri'])

        # OAuthRequest will strip our query parameters, so add them back in.
        parts = list(urlparse.urlparse(self._location))
        queryargs = cgi.parse_qs(parts[4], keep_blank_values=True)
        for key, value in queryargs.iteritems():
            orq.set_parameter(key, value[0])

        # Sign the request.
        osm = OAuthSignatureMethod_HMAC_SHA1()
        orq.set_parameter('oauth_signature_method', osm.get_name())
        orq.sign_request(osm, csr, None)

        if method == 'GET':
            request['uri'] = orq.to_url()
        else:
            request['headers'].update(orq.to_header())

        return request
开发者ID:Aurink0,项目名称:remoteobjects,代码行数:28,代码来源:netflix.py

示例6: fetch_url

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
	def fetch_url(self, url, token, **kwargs):
		from StringIO import StringIO
		
		token = OAuthToken.from_string(str(token))
		consumer = self.get_consumer()
		connection = self.get_connection(False)
		
		request = OAuthRequest.from_consumer_and_token(
			consumer, token = token, http_method = 'GET',
			http_url = url, parameters = kwargs
		)
		
		request.sign_request(self.signature_method, consumer, token)
		url = request.to_url()
		start = 'http://%s' % self.server
		
		if url.startswith(start):
			url = url[len(start):]
		
		start = 'https://%s' % self.server
		if url.startswith(start):
			url = url[len(start):]
		
		connection.request(request.http_method, url, '', request.to_header())
		resp = connection.getresponse().read()
		return StringIO(resp)
开发者ID:flamingtarball,项目名称:bambu-tools,代码行数:28,代码来源:__init__.py

示例7: exchange_request_token

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
def exchange_request_token(request_token):
    consumer = OAuthConsumer(settings.ORCHARD_KEY, settings.ORCHAR_SECRET)
    oauth_request = OAuthRequest.from_consumer_and_token(
        consumer, request_token, http_url=ACCESS_TOKEN_URL)

    return OAuthToken.from_string(
        _make_request(consumer, oauth_request, request_token))
开发者ID:roddyr2,项目名称:Icon-Metrics,代码行数:9,代码来源:api.py

示例8: request

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def request(self, url, token=None, verb='GET', filename=None, **args):
        """`url` may be relative with regard to Netflix. Verb is a
        HTTP verb.

        """
        if isinstance(url, NetflixObject) and not isinstance(url, basestring):
            url = url.id
        if not url.startswith('http://'):
            url = self.protocol + self.host + url
        if 'output' not in args:
            args['output'] = 'json'
        args['method'] = verb.upper()

        postbody = None
        if verb.upper() == 'POST':
            args['method'] = 'GET'
            postbody = '&'.join(['%s=%s' % (escape(str(k)), escape(str(v))) \
                for k, v in args.iteritems()])
            args = {}

        # we don't want unicode in the parameters
        for k,v in args.iteritems():
            try:
                args[k] = v.encode('utf-8')
            except AttributeError:
                pass

        oa_req = OAuthRequest.from_consumer_and_token(self.consumer,
                                                      http_url=url,
                                                      parameters=args,
                                                      token=token)
        oa_req.sign_request(self.signature_method,
                            self.consumer,
                            token)
        if filename is None:
            def do_request():
                req = self.http.urlopen(verb, oa_req.to_url(), body=postbody)
                if not str(req.status).startswith('2'):
                    self.analyze_error(req)
                return req
        else:
            def do_request():
                try:
                    subprocess.check_call(["curl", oa_req.to_url(),
                                           "--location",
                                           "--compressed",
                                           "--output", filename])
                    sys.stderr.write('\nSaved to: %s\n' % filename)
                except OSError:
                    raise RuntimeError, "You need to have curl installed to use this command"
        try:
            req = do_request()
        except TooManyRequestsPerSecondError:
            time.sleep(1)
            req = do_request()
        if filename:
            return
        o = json.loads(req.data, object_hook=self.object_hook)
        return o
开发者ID:kdeloach,项目名称:python-netflix,代码行数:61,代码来源:__init__.py

示例9: get_access_token

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
 def get_access_token(self, code):
     parameters = {}
     parameters['client_id'] = GITHUB_CLIENT_ID
     parameters['client_secret'] = GITHUB_CLIENT_SECRET
     parameters['code'] = code
     oauth_request = OAuthRequest.from_consumer_and_token(self.consumer, http_url=GITHUB_ACCESS_TOKEN_URL, parameters=parameters)
     access_token = get_response_from_url(oauth_request.to_url())       
     return access_token
开发者ID:Andy1914,项目名称:Maggie,代码行数:10,代码来源:github.py

示例10: begin

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def begin(self, request, data):
        """
        Try to get Request Token from OAuth Provider and 
        redirect user to provider's site for approval.
        """
        consumer = OAuthConsumer(self.CONSUMER_KEY, self.CONSUMER_SECRET)
        signature_method = OAuthSignatureMethod_HMAC_SHA1()
        callback = request.build_absolute_uri(reverse('publicauth-complete', args=[self.provider]))
        oauth_req = OAuthRequest.from_consumer_and_token(consumer, callback=callback, http_url=self.REQUEST_TOKEN_URL)
        oauth_req.sign_request(signature_method, consumer, None)
        response = urllib.urlopen(oauth_req.to_url()).read()

        token = OAuthToken.from_string(response) # instatiate token

        oauth_req = OAuthRequest.from_consumer_and_token(consumer, token, http_url=self.AUTHORIZE_URL)
        oauth_req.sign_request(signature_method, consumer, token)
        raise Redirect(oauth_req.to_url())
开发者ID:diver-in-sky,项目名称:django-publicauth,代码行数:19,代码来源:oauth.py

示例11: make_requests_from_url

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def make_requests_from_url(self, url):
        oauth_request = OAuthRequest.from_consumer_and_token(
                                            self.consumer,
                                            token=self.token,
                                            http_method='GET',
                                            http_url=url)
        oauth_request.sign_request(self.signature, self.consumer, self.token)

        return Request(oauth_request.to_url(), callback=self.parse, dont_filter=True)
开发者ID:c0ffee,项目名称:couch-crawler,代码行数:11,代码来源:yammer.py

示例12: get_authorisation_url

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
	def get_authorisation_url(self, consumer = None, token = None):
		if self.token_required and (not consumer and not token):
			raise Exception('Consumer and token are required')
		
		oauth_request = OAuthRequest.from_consumer_and_token(
			consumer, token = token, http_url = self.authorise_url
		)
		
		oauth_request.sign_request(self.signature_method, consumer, token)
		return oauth_request.to_url()
开发者ID:flamingtarball,项目名称:bambu-tools,代码行数:12,代码来源:__init__.py

示例13: get_request_token

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
 def get_request_token(self):
     oa_req = OAuthRequest.from_consumer_and_token(
         self.consumer,
         http_url=self.request_token_url)
     oa_req.sign_request(self.signature_method,
                               self.consumer,
                               None)
     req = self.http.get_url(self.request_token_url, headers = oa_req.to_header())
     if not str(req.status).startswith('2'):
         self.analyze_error(req)
     return OAuthToken.from_string(req.data)
开发者ID:kdeloach,项目名称:python-netflix,代码行数:13,代码来源:__init__.py

示例14: oauth_request

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
    def oauth_request(self, token, url, extra_params=None):
        """Generate OAuth request, setups callback url"""
        params = {"oauth_callback": self.redirect_uri}
        if extra_params:
            params.update(extra_params)

        if "oauth_verifier" in self.data:
            params["oauth_verifier"] = self.data["oauth_verifier"]
        request = OAuthRequest.from_consumer_and_token(self.consumer, token=token, http_url=url, parameters=params)
        request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, token)
        return request
开发者ID:justquick,项目名称:django-social-auth,代码行数:13,代码来源:__init__.py

示例15: fetch_access_token

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import from_consumer_and_token [as 别名]
def fetch_access_token(request, consumer, request_token, url, parameters=None, 
                        sig_method=None):
  parameters = parameters and parameters or {}
  sig_method = sig_method and sig_method or LocalOAuthSignatureMethod_RSA_SHA1()
 
  logging.info('* Obtain an access token ...')
  oauth_request = OAuthRequest.from_consumer_and_token(
      consumer, request_token, http_url=url, parameters=parameters
      )
  oauth_request.sign_request(sig_method, consumer, None)
  
  return _fetch_token(oauth_request)
开发者ID:noutrela,项目名称:jaikuenginepatch,代码行数:14,代码来源:oauth_util.py


注:本文中的oauth.oauth.OAuthRequest.from_consumer_and_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。