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


Python OAuthRequest.sign_request方法代码示例

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


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

示例1: updateProfile

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def updateProfile(token, secret, update_profile_url, profile):
    current_site = Site.objects.get_current()
    user_profile_url = "%s%s" % (current_site.domain, reverse('profile_detail', args=[profile.user.username]))
    oauthToken = OAuthToken(token, secret)
    url = urlparse.urlparse(update_profile_url)
    params = {}
    if url[4] != '':
        # We need to copy over the query string params for sites like laconica
        params.update(dict([part.split('=') for part in url[4].split('&')]))
    params['omb_version'] = OMB_VERSION_01
    params['omb_listenee'] = user_profile_url
    params['omb_listenee_profile'] = user_profile_url
    params['omb_listenee_nickname'] = profile.username
    params['omb_listenee_license'] = '%s/license/' % current_site.domain # TODO link to the real license
    params['omb_listenee_fullname'] = profile.name
    params['omb_listenee_homepage'] = profile.website
    params['omb_listenee_bio'] = profile.about
    params['omb_listenee_location'] = profile.location
    #params['omb_listenee_avatar'] = TODO get the gravatar of the user
    
    consumer = OAuthConsumer(current_site.domain, "")
    req = OAuthRequest().from_consumer_and_token(consumer, token=oauthToken, http_url=url.geturl(), parameters=params, http_method="POST")
    req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, oauthToken)
    f = urllib.urlopen(url.geturl(), req.to_postdata())
    data = f.read()
    # TODO log failures
开发者ID:duy,项目名称:django-omb,代码行数:28,代码来源:oauthConsumer.py

示例2: requestAuthorization

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def requestAuthorization(token, url, listener, user):
    current_site = Site.objects.get_current()
    user_profile_url = "%s%s" % (current_site.domain, reverse('profile_detail', args=[user.username]))
    profile = user.get_profile()
    url = urlparse.urlparse(url)
    params = {}
    if url[4] != '':
        # We need to copy over the query string params for sites like laconica
        params.update(dict([part.split('=') for part in url[4].split('&')]))
    params['omb_version'] = OMB_VERSION_01
    params['omb_listener'] = listener
    params['omb_listenee'] = "http://%s" % user_profile_url
    params['omb_listenee_profile'] = "http://%s" % user_profile_url
    params['omb_listenee_nickname'] = user.username
    params['omb_listenee_license'] = 'http://%s/license/' % current_site.domain # TODO link to the real license
    params['omb_listenee_fullname'] = "%s %s" % (user.first_name, user.last_name)
    params['omb_listenee_homepage'] = "" # TOOD Pinax doesn't have this
    params['omb_listenee_bio'] = profile.about
    params['omb_listenee_location'] = profile.location
    params['omb_listenee_avatar'] = '' # TODO get the avatar url
    params['oauth_callback'] = 'http://%s/omb/finish_follow/' % current_site.domain
    consumer = OAuthConsumer(current_site.domain, "")
    oauth_request = OAuthRequest().from_consumer_and_token(consumer, http_url=url.geturl(), parameters=params, http_method="GET", token=token)
    oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, token)
    return oauth_request
开发者ID:duy,项目名称:django-omb,代码行数:27,代码来源:oauthConsumer.py

示例3: requestToken

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def requestToken(omb):
    current_site = Site.objects.get_current()
    url = urlparse.urlparse(omb[OAUTH_REQUEST].uris[0].uri)
    params = {}
    if url[4] != '':
        # We need to copy over the query string params for sites like laconica
        params.update(dict([part.split('=') for part in url[4].split('&')]))
    params['omb_version'] = OMB_VERSION_01
    params['omb_listener'] = omb[OAUTH_REQUEST].localid.text
    consumer = OAuthConsumer(current_site.domain, "")
    req = OAuthRequest().from_consumer_and_token(consumer, http_url=url.geturl(), parameters=params, http_method="POST")
    req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
    f = urllib.urlopen(url.geturl(), req.to_postdata())
    data = f.read()
    requestToken = OAuthToken.from_string(data)
    return requestToken
开发者ID:duy,项目名称:django-omb,代码行数:18,代码来源:oauthConsumer.py

示例4: requestAccessToken

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def requestAccessToken(omb_session, oauth_request):
    current_site = Site.objects.get_current()
    token = OAuthToken(omb_session["token"], omb_session["secret"])
    url = urlparse.urlparse(omb_session["access_token_url"])
    params = {}
    if url[4] != '':
        # We need to copy over the query string params for sites like laconica
        params.update(dict([part.split('=') for part in url[4].split('&')]))
    params['omb_version'] = OMB_VERSION_01
    consumer = OAuthConsumer(current_site.domain, "")
    req = OAuthRequest().from_consumer_and_token(consumer, token=token, http_url=url.geturl(), parameters=params, http_method="POST")
    req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, token)
    f = urllib.urlopen(url.geturl(), req.to_postdata())
    data = f.read()
    accessToken = OAuthToken.from_string(data)
    return accessToken
开发者ID:duy,项目名称:django-omb,代码行数:18,代码来源:oauthConsumer.py

示例5: _compose_auth_header

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
 def _compose_auth_header(self, url):
     """Return additional header entries for request to `url`."""
     params = {
         'oauth_version': "1.0",
         'oauth_nonce': generate_nonce(),
         'oauth_timestamp': int(time()),
         'oauth_token': self.token.key,
         'oauth_consumer_key': self.consumer.key,
     }
     req = OAuthRequest(http_url=url, parameters=params)
     req.sign_request(
         OAuthSignatureMethod_PLAINTEXT(), self.consumer, self.token)
     header = req.to_header()
     # Django uses the 'HTTP_AUTHORIZATION' to look up Authorization
     # credentials.
     header['HTTP_AUTHORIZATION'] = header['Authorization']
     return header
开发者ID:deepakhajare,项目名称:maas,代码行数:19,代码来源:oauthclient.py

示例6: start_auth

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def start_auth(request, fail_redirect='/account/other_services/'):
    consumer = OAuthConsumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
    # Request the OAuth Token
    req = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_REQUEST_TOKEN_URL,
        parameters={}, http_method="POST")
    req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, None)
    try:
        res = urllib.urlopen(TWITTER_REQUEST_TOKEN_URL, req.to_postdata())
        requestToken = OAuthToken.from_string(res.read())
        # Authorise the OAuth Token
        oauth_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_AUTHORIZE_URL, 
            parameters={}, http_method="GET", token=requestToken)
        oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, requestToken)
        return HttpResponseRedirect(oauth_request.to_url())
    except IOError:
        request.user.message_set.create(
            message=ugettext(u"Twitter authorization failed.")
        )
        return HttpResponseRedirect(fail_redirect)
开发者ID:skabber,项目名称:django-twitterauth,代码行数:21,代码来源:views.py

示例7: postNotice

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def postNotice(token, secret, post_notice_url, notice_content, notice_url, user):
    current_site = Site.objects.get_current()
    user_profile_url = "%s%s" % (current_site.domain, reverse('profile_detail', args=[user.username]))
    oauthToken = OAuthToken(token, secret)
    url = urlparse.urlparse(post_notice_url)
    params = {}
    if url[4] != '':
        # We need to copy over the query string params for sites like laconica
        params.update(dict([part.split('=') for part in url[4].split('&')]))
    params['omb_version'] = OMB_VERSION_01
    params['omb_listenee'] = user_profile_url
    params['omb_notice'] = "%s%s" % (current_site.domain, notice_url)
    params['omb_notice_content'] = notice_content
    params['omb_notice_url'] = "%s%s" % (current_site.domain, notice_url)
    params['omb_notice_license'] = '%s/license/' % current_site.domain # TODO link to the real license
    
    consumer = OAuthConsumer(current_site.domain, "")
    req = OAuthRequest().from_consumer_and_token(consumer, token=oauthToken, http_url=url.geturl(), parameters=params, http_method="POST")
    req.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, oauthToken)
    f = urllib.urlopen(url.geturl(), req.to_postdata())
    data = f.read()
开发者ID:duy,项目名称:django-omb,代码行数:23,代码来源:oauthConsumer.py

示例8: get_credentials_from_request

# 需要导入模块: from oauth.oauth import OAuthRequest [as 别名]
# 或者: from oauth.oauth.OAuthRequest import sign_request [as 别名]
def get_credentials_from_request(request):
    token = OAuthToken(request.GET.get("oauth_token"), "")
    consumer = OAuthConsumer(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
    oauth_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_REQUEST_ACCESS_TOKEN_URL,
        parameters={}, http_method="GET", token=token)
    oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, token)
    try:
        res = urllib.urlopen(TWITTER_REQUEST_ACCESS_TOKEN_URL, oauth_request.to_postdata())
        accessToken = OAuthToken.from_string(res.read())
        # verify the access token
        verify_request = OAuthRequest().from_consumer_and_token(consumer, http_url=TWITTER_VERIFY_CREDENTIALS,
            http_method="GET", token=accessToken)
        verify_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), consumer, accessToken)
        res = urllib.urlopen(verify_request.to_url())
        json_response = simplejson.loads(res.read())
        if json_response['screen_name']:
            return accessToken
            request.user.message_set.create(
                message=ugettext(u"Twitter authorization failed.")
            )
    except IOError:
        request.user.message_set.create(
            message=ugettext(u"Twitter authorization failed.")
        )
开发者ID:skabber,项目名称:django-twitterauth,代码行数:26,代码来源:views.py


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