當前位置: 首頁>>代碼示例>>Python>>正文


Python oauth2.Token方法代碼示例

本文整理匯總了Python中oauth2.Token方法的典型用法代碼示例。如果您正苦於以下問題:Python oauth2.Token方法的具體用法?Python oauth2.Token怎麽用?Python oauth2.Token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauth2的用法示例。


在下文中一共展示了oauth2.Token方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: login

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def login(self, username, password):
        '''Authenticate using XAuth variant of OAuth.

        :param str username: Username or email address for the relevant account
        :param str password: Password for the account
        '''
        response = self.request(
            ACCESS_TOKEN,
            {
                'x_auth_mode': 'client_auth',
                'x_auth_username': username,
                'x_auth_password': password
            },
            returns_json=False
        )
        token = dict(parse_qsl(response['data'].decode()))
        self.token = oauth.Token(
            token['oauth_token'], token['oauth_token_secret'])
        self.oauth_client = oauth.Client(self.consumer, self.token) 
開發者ID:mdorn,項目名稱:pyinstapaper,代碼行數:21,代碼來源:instapaper.py

示例2: __init__

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def __init__(self, key, secret, email, password, cartodb_domain, host='carto.com', protocol='https', proxy_info=None, *args, **kwargs):
        super(CartoDBOAuth, self).__init__(cartodb_domain, host, protocol, *args, **kwargs)

        self.consumer_key = key
        self.consumer_secret = secret
        consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)

        client = oauth.Client(consumer, proxy_info=proxy_info)
        client.set_signature_method = oauth.SignatureMethod_HMAC_SHA1()

        params = {}
        params["x_auth_username"] = email
        params["x_auth_password"] = password
        params["x_auth_mode"] = 'client_auth'

        # Get Access Token
        access_token_url = ACCESS_TOKEN_URL % {'user': cartodb_domain, 'domain': host, 'protocol': protocol}
        resp, token = client.request(access_token_url, method="POST", body=urllib.urlencode(params))
        access_token = dict(urlparse.parse_qsl(token))
        token = oauth.Token(access_token['oauth_token'], access_token['oauth_token_secret'])

        # prepare client
        self.client = oauth.Client(consumer, token) 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:25,代碼來源:cartodb.py

示例3: oauth_login

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def oauth_login(self, url, oauth_token, oauth_token_secret,
                    consumer_key='anonymous', consumer_secret='anonymous'):
        """Authenticate using the OAUTH method.

        This only works with IMAP servers that support OAUTH (e.g. Gmail).
        """
        if oauth_module:
            token = oauth_module.Token(oauth_token, oauth_token_secret)
            consumer = oauth_module.Consumer(consumer_key, consumer_secret)
            xoauth_callable = lambda x: oauth_module.build_xoauth_string(url,
                                                                         consumer,
                                                                         token)
            return self._command_and_check('authenticate', 'XOAUTH',
                                           xoauth_callable, unpack=True)
        else:
            raise self.Error(
                'The optional oauth2 package is needed for OAUTH authentication') 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:19,代碼來源:imapclient.py

示例4: callback

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def callback():

    global req_token
    global consumer

    config = read_config()

    oauth_verifier = request.args.get('oauth_verifier', '')

    token = oauth.Token(req_token.oauth_token,
                        req_token.oauth_token_secret)

    token.set_verifier(oauth_verifier)

    client = oauth.Client(consumer, token)

    resp, content = client.request(config.access_token_url, 'POST')
    access_token = dict(parse_qsl(content.decode('utf-8')))

    with open('.twitterauth', 'w') as req_auth:
        file_content = yaml.dump(access_token, default_flow_style=False)
        req_auth.write(file_content)

    return 'All set! You can close the browser window and stop the server.' 
開發者ID:PacktPublishing,項目名稱:Python-Programming-Blueprints,代碼行數:26,代碼來源:twitter_auth.py

示例5: make_request

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def make_request(self, url, method="GET", body="", headers=None):
        """Makes a request to the TradeKing API."""

        consumer = Consumer(key=TRADEKING_CONSUMER_KEY,
                            secret=TRADEKING_CONSUMER_SECRET)
        token = Token(key=TRADEKING_ACCESS_TOKEN,
                      secret=TRADEKING_ACCESS_TOKEN_SECRET)
        client = Client(consumer, token)

        body_bytes = body.encode("utf-8")
        self.logs.debug("TradeKing request: %s %s %s %s" %
                        (url, method, body_bytes, headers))
        response, content = client.request(url, method=method,
                                           body=body_bytes,
                                           headers=headers)
        self.logs.debug("TradeKing response: %s %s" % (response, content))

        try:
            return loads(content)
        except ValueError:
            self.logs.error("Failed to decode JSON response: %s" % content)
            return None 
開發者ID:maxbbraun,項目名稱:trump2cash,代碼行數:24,代碼來源:trading.py

示例6: use_access_token

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def use_access_token(oauth_token, oauth_secret):
    consumer = oauth.Consumer(key='9fdce0e111a1489eb5a42eab7a84306b', secret='liqutXmqJpKmetfs')
    token = oauth.Token(oauth_token, oauth_secret)
    oauth_request = oauth.Request.from_consumer_and_token(consumer, http_url=RESOURCE_URL)
    oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)

    # get the resource
    response = requests.get(RESOURCE_URL, headers=oauth_request.to_header())
    return response.text 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:11,代碼來源:demo4_use_access_token.py

示例7: get_access_token

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def get_access_token(oauth_token, oauth_secret, oauth_verifier):
    consumer = oauth.Consumer(key='9fdce0e111a1489eb5a42eab7a84306b', secret='liqutXmqJpKmetfs')
    token = oauth.Token(oauth_token, oauth_secret)
    token.set_verifier(oauth_verifier)
    oauth_request = oauth.Request.from_consumer_and_token(consumer, token, http_url=ACCESS_TOKEN_URL)
    oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)
    response = requests.get(ACCESS_TOKEN_URL, headers=oauth_request.to_header())
    access_token = dict(urllib.parse.parse_qsl(response.content.decode('utf8')))

    return access_token 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:12,代碼來源:demo3_get_access_token.py

示例8: authenticate

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        self.docmd('AUTH', 'XOAUTH %s' % \
            base64.b64encode(oauth2.build_xoauth_string(url, consumer, token))) 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:11,代碼來源:smtp.py

示例9: authenticate

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def authenticate(self, url, consumer, token):
        if consumer is not None and not isinstance(consumer, oauth2.Consumer):
            raise ValueError("Invalid consumer.")

        if token is not None and not isinstance(token, oauth2.Token):
            raise ValueError("Invalid token.")

        imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH',
            lambda x: oauth2.build_xoauth_string(url, consumer, token)) 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:11,代碼來源:imap.py

示例10: prepare_request

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def prepare_request(url, url_params):
    reqconfig = read_reqauth()
    config = read_config()

    token = oauth.Token(
        key=reqconfig.oauth_token,
        secret=reqconfig.oauth_token_secret)

    consumer = oauth.Consumer(
        key=config.consumer_key,
        secret=config.consumer_secret)

    params = {
        'oauth_version': "1.0",
        'oauth_nonce': oauth.generate_nonce(),
        'oauth_timestamp': str(int(time.time()))
    }

    params['oauth_token'] = token.key
    params['oauth_consumer_key'] = consumer.key

    params.update(url_params)

    req = oauth.Request(method="GET", url=url, parameters=params)

    signature_method = oauth.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, token)

    return req.to_url() 
開發者ID:PacktPublishing,項目名稱:Python-Programming-Blueprints,代碼行數:31,代碼來源:request.py

示例11: __init__

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def __init__(self, consumer, token, user_agent):
    """
    consumer   - An instance of oauth.Consumer.
    token      - An instance of oauth.Token constructed with
                 the access token and secret.
    user_agent - The HTTP User-Agent to provide for this application.
    """
    self.consumer = consumer
    self.token = token
    self.user_agent = user_agent
    self.store = None

    # True if the credentials have been revoked
    self._invalid = False 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:16,代碼來源:oauth.py

示例12: step2_exchange

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def step2_exchange(self, verifier):
    """Exhanges an authorized request token
    for OAuthCredentials.

    Args:
      verifier: string, dict - either the verifier token, or a dictionary
        of the query parameters to the callback, which contains
        the oauth_verifier.
    Returns:
       The Credentials object.
    """

    if not (isinstance(verifier, str) or isinstance(verifier, unicode)):
      verifier = verifier['oauth_verifier']

    token = oauth.Token(
        self.request_token['oauth_token'],
        self.request_token['oauth_token_secret'])
    token.set_verifier(verifier)
    consumer = oauth.Consumer(self.consumer_key, self.consumer_secret)
    client = oauth.Client(consumer, token)

    headers = {
        'user-agent': self.user_agent,
        'content-type': 'application/x-www-form-urlencoded'
    }

    uri = _oauth_uri('access', self.discovery, self.params)
    resp, content = client.request(uri, 'POST', headers=headers)
    if resp['status'] != '200':
      logging.error('Failed to retrieve access token: %s', content)
      raise RequestError('Invalid response %s.' % resp['status'])

    oauth_params = dict(parse_qsl(content))
    token = oauth.Token(
        oauth_params['oauth_token'],
        oauth_params['oauth_token_secret'])

    return OAuthCredentials(consumer, token, self.user_agent) 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:41,代碼來源:oauth.py

示例13: __init__

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def __init__(self, consumer_key, consumer_secret, token_key, token_secret):
        consumer = Consumer(key=consumer_key, secret=consumer_secret)
        token = Token(key=token_key, secret=token_secret)

        proxy_info = None
        if hasattr(settings, 'PROXY_HOST') and \
                hasattr(settings, 'PROXY_PORT'):
            proxy_info = ProxyInfo(
                proxy_type=PROXY_TYPE_HTTP,
                proxy_host=settings.PROXY_HOST,
                proxy_port=settings.PROXY_PORT)
        self.client = Client(
            consumer=consumer,
            token=token,
            proxy_info=proxy_info) 
開發者ID:Gandi,項目名稱:baobab,代碼行數:17,代碼來源:authentication.py

示例14: lrs_oauth_callback

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def lrs_oauth_callback(request):
    import os
    import urlparse

    user_id = request.user.id
    user = User.objects.get(id=user_id)

    status = request.GET.get('status')
    if status is not None and status == 'fail':
        return HttpResponseServerError('Could not get access token.')

    request_token = OAuthTempRequestToken.objects.get(user_id=user)
    verifier = request.GET.get('oauth_verifier')

    token = oauth.Token(request_token.token, request_token.secret)
    request_token.delete() #delete temp token
    token.set_verifier(verifier)

    # Get Consumer info #Todo: change (most definitely) (IMPORTANT!!)
    # consumer_key, consumer_secret = get_consumer_key_and_secret()
    app = ClientApp.objects.get(id = request_token.clientapp.id)
    client = oauth.Client(oauth.Consumer(app.get_key(), app.get_secret()), token)

    # Exchange request_token for authed and verified access_token
    resp,content = client.request(app.get_access_token_url(), "POST")
    access_token = dict(urlparse.parse_qsl(content))

    if access_token['oauth_token']:
        UserAccessToken_LRS(user=user, access_token=access_token['oauth_token'],
                            access_token_secret=access_token['oauth_token_secret'],
                            clientapp = app).save()
        from django.shortcuts import render_to_response
        return render_to_response('xapi/get_access_token_successful.html') 
開發者ID:kirstykitto,項目名稱:CLAtoolkit,代碼行數:35,代碼來源:views.py

示例15: to_string

# 需要導入模塊: import oauth2 [as 別名]
# 或者: from oauth2 import Token [as 別名]
def to_string(self):
        return oauth.Token(self.api_key, self.secret_key).to_string() 
開發者ID:apache,項目名稱:allura,代碼行數:4,代碼來源:oauth.py


注:本文中的oauth2.Token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。