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


Python oauth.OAuthToken类代码示例

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


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

示例1: oauth_callback

def oauth_callback(request):
    print 'In oauth_callback'
    oauth_token    = request.GET['oauth_token']
    oauth_secret   = request.GET['oauth_token_secret']
    oauth_verifier = request.GET['oauth_verifier']

    request_token = OAuthToken(oauth_token, oauth_secret)
    request_token.set_verifier(oauth_verifier)
    
    request.session['request_token']  = request_token
    
    # We do this before we redirect so that there's no "limbo" state where the
    # user has a request token but no access token.
    access_token = CLIENT.fetch_access_token(request_token)
    request.session['oauth_token_string'] = access_token.to_string()
    print "Access token is %s" % access_token.to_string()
    
    profile = request.user.get_profile()
    profile.access_token = access_token.to_string()
    profile.save()

    print "Your account has been associated with Khan Academy username %s" % access_token.to_string()

    # We're done authenticating, and the credentials are now stored in the
    # session. We can redirect back home.
    return HttpResponseRedirect('/homeroom')
开发者ID:TheKNetwork,项目名称:Codename-K,代码行数:26,代码来源:views.py

示例2: do_GET

 def do_GET(self):
     global REQUEST_TOKEN
     params = cgi.parse_qs(self.path.split('?', 1)[1], keep_blank_values=False)
     REQUEST_TOKEN = OAuthToken(params['oauth_token'][0], params['oauth_token_secret'][0])
     REQUEST_TOKEN.set_verifier(params['oauth_verifier'][0])
     self.send_response(200)
     self.send_header('Content-Type', 'text/plain')
     self.end_headers()
     self.wfile.write('OAuth request token fetched; you can close this window.')
开发者ID:xmarcosx,项目名称:khan-api,代码行数:9,代码来源:test.py

示例3: do_GET

            def do_GET(self):
                global REQUEST_TOKEN
                params = cgi.parse_qs(self.path.split("?", 1)[1], keep_blank_values=False)
                REQUEST_TOKEN = OAuthToken(params["oauth_token"][0], params["oauth_token_secret"][0])
                REQUEST_TOKEN.set_verifier(params["oauth_verifier"][0])

                self.send_response(200)
                self.send_header("Content-Type", "text/plain")
                self.end_headers()
                self.wfile.write("OAuth request token fetched; you can close this window.")
开发者ID:biffhero,项目名称:KhanReporter,代码行数:10,代码来源:KhanOAuthConnector.py

示例4: execute_khan_api_method

def execute_khan_api_method(profile_access_token, api_method, cache_timeout=(60 * 60 * 2), 
                            force_refresh=False, return_raw_text=False, user_id=None, 
                            disk_cache=True, cache_per_user=True):
    
    cache_key = ""
    _chosen_cache = get_cache('default')
    if disk_cache:
        _chosen_cache = get_cache('disk')
    
    if cache_per_user:
        if user_id is not None:
            cache_key = "%s^%s^%s" % (user_id, api_method, return_raw_text)
        else:
            cache_key = "%s^%s^%s" % (profile_access_token, api_method, return_raw_text)
    else:
        cache_key = "%s^%s" % (api_method, return_raw_text)
    
    cache_key = cache_key.replace("/","^")
    cache_key = cache_key.replace(".","^")
    cache_key = cache_key.replace(":","^")
    cache_key = cache_key.replace(" ","^")
    
    cache_hit = False
    result_data = _chosen_cache.get(cache_key)
    
    if force_refresh or result_data is None:
        resource = CLIENT.access_api_resource(
            api_method,
            access_token = OAuthToken.from_string(profile_access_token),
            method = "GET"
            )
        
        text = resource['body']
        
        # Error messages can contain HTML. Escape them so they're not rendered.
        is_html = has_text_html_header(resource['headers'])
        if is_html:
            text = cgi.escape(text)
        
        print text
        
        try:
            if return_raw_text:
                result_data = text
            else:
                result_data = simplejson.loads(text)
                
            _chosen_cache.set(cache_key, result_data, cache_timeout)
        except:
            print "exception storing in cache"
        
    else:
        # print "Got json data from cache!"
        cache_hit = True
    
    if not cache_hit:
        # update local tables with fresh data
        print "(cache not hit or is empty: Update local tables with data)"
    
    return result_data
开发者ID:TheKNetwork,项目名称:Codename-K,代码行数:60,代码来源:khan_api.py

示例5: fireeagle

def fireeagle( request ):
    if request.user.fireeagle_token:
        if 'next' in request.session:
            next = request.session['next']
            del request.session['next']
        else:
            next = "/"
        return HttpResponseRedirect( next )

    if not 'oauth_token' in request.GET:
        apptoken = fe.request_token()
        request.session['apptoken'] = apptoken.to_string()
        auth_url = fe.authorize( apptoken )
        if request.session['mobile']:
            auth_url = re.sub(r'https://fireeagle.yahoo.net/', "https://m.fireeagle.yahoo.net/", auth_url)
        logging.info("Redirecting to %s for auth"%auth_url)
        return HttpResponseRedirect( auth_url )

    else:
        apptoken = OAuthToken.from_string( request.session['apptoken'] )
        user_token = fe.access_token( apptoken )
        request.user.fireeagle_token = user_token.to_string()
        request.user.location_from_fireeagle( fe )
        request.user.save()
        if 'next' in request.session:
            next = request.session['next']
            del request.session['next']
        else:
            next = "/"
        return HttpResponseRedirect( next )
开发者ID:tominsam,项目名称:herejustnow,代码行数:30,代码来源:account.py

示例6: get_access_token

 def get_access_token(self, request_token):
     url = API_HOME + '/oauth/access_token'
     client = OAuthClient(self.consumer, token=request_token)
     resp, content = client.request(url)
     if resp['status'] != '200':
         raise Exception("Invalid response %s." % resp['status'])
     return OAuthToken.from_string(content)
开发者ID:roymax,项目名称:py-sinaly,代码行数:7,代码来源:__init__.py

示例7: exchange_request_token_for_access_token

 def exchange_request_token_for_access_token(self, request_token, verifier):
     parameters = {"oauth_verifier": verifier}
     oauth_request = self.build_oauth_request(
         self.get_access_token_url(), request_token, parameters=parameters
     )
     response = self.execute(oauth_request)
     return OAuthToken.from_string(response)
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:7,代码来源:oauth_tools.py

示例8: fetch_request_token

 def fetch_request_token(self, oauth_request):
     # via headers
     # -> OAuthToken
     self.connection.request(oauth_request.http_method, self.request_token_url, headers=oauth_request.to_header())
     response = self.connection.getresponse()
     if response.status != 200:
         raise Exception("Error making request: " + str(response.read()))
     return OAuthToken.from_string(response.read())
开发者ID:swarbhanu,项目名称:ion-ux,代码行数:8,代码来源:OAuthUtilities.py

示例9: get_request_token

 def get_request_token(self, callback=None):
     url = API_HOME + '/oauth/request_token'
     client = OAuthClient(self.consumer) 
     resp, content =  client.request(url, callback=callback,
                                     force_auth_header=False) 
     if resp['status'] != '200':
         raise Exception("Invalid response %s." % resp['status'])
     return OAuthToken.from_string(content)
开发者ID:roymax,项目名称:py-sinaly,代码行数:8,代码来源:__init__.py

示例10: exchange_request_token_for_access_token

 def exchange_request_token_for_access_token(self, token):
     oauth_request = OAuthRequest.from_consumer_and_token(self.consumer,
             token=token, http_url=URL_OAUTH_ACCESS_TOKEN)
     oauth_request.sign_request(self.signature_method, self.consumer,
             token)
     resp = self.oauth_fetch(oauth_request, raw=True)
     self.access_token = OAuthToken.from_string(resp) 
     return self.access_token
开发者ID:afternoon,项目名称:followize,代码行数:8,代码来源:twitter.py

示例11: oauth_callback

def oauth_callback():
    oauth_token    = request.args.get('oauth_token',  '')
    oauth_secret   = request.args.get('oauth_token_secret', '')
    oauth_verifier = request.args.get('oauth_verifier', '')

    request_token = OAuthToken(oauth_token, oauth_secret)
    request_token.set_verifier(oauth_verifier)
    
    session['request_token']  = request_token
    
    # We do this before we redirect so that there's no "limbo" state where the
    # user has a request token but no access token.
    access_token = CLIENT.fetch_access_token(request_token)
    session['oauth_token_string'] = access_token.to_string()

    # We're done authenticating, and the credentials are now stored in the
    # session. We can redirect back home.
    return redirect(url_for('.index'))
开发者ID:hsingh23,项目名称:khan-api,代码行数:18,代码来源:explorer.py

示例12: is_authenticated

 def is_authenticated(self, access_token):
     if not isinstance(access_token, OAuthToken):
         access_token = OAuthToken.from_string(access_token)
     oauth_request = self.build_oauth_request(self.check_auth_url, access_token)
     response = json.loads(self.execute(oauth_request))
     if "screen_name" in response:
         self.set_access_token(access_token)
         return response["screen_name"]
     return False
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:9,代码来源:twitter.py

示例13: get_unauthorized_request_token

 def get_unauthorized_request_token(self, oauth_callback=None):
     parameters = {}
     if oauth_callback:
         parameters = {"oauth_callback": oauth_callback}
     oauth_request = self.build_oauth_request(
         self.get_request_token_url(), parameters = parameters
     )
     response = self.execute(oauth_request)
     return OAuthToken.from_string(response)
开发者ID:sunsuk7tp,项目名称:oauthlib,代码行数:9,代码来源:oauth_tools.py

示例14: fetch_access_token

    def fetch_access_token(self, oauth_request):
        # via headers
        # -> OAuthToken
        self.connection.request(oauth_request.http_method, self.access_token_url, headers=oauth_request.to_header())
        response = self.connection.getresponse()
        if response.status != 200:
            logging.warn("Error temp cred -- response from server:\n" + response.read())
            raise Exception("Error: did not get a temp cred. Response code=" + str(response.status))

        return OAuthToken.from_string(response.read())
开发者ID:swarbhanu,项目名称:ion-ux,代码行数:10,代码来源:OAuthUtilities.py

示例15: fetch_access_token

    def fetch_access_token(self, request_token):

        oauth_request = OAuthRequest.from_consumer_and_token(
            self.consumer, token=request_token, http_url="%s/api/auth/access_token" % self.server_url
        )

        oauth_request.sign_request(OAuthSignatureMethod_HMAC_SHA1(), self.consumer, request_token)

        response = get_response(oauth_request.to_url())

        return OAuthToken.from_string(response)
开发者ID:mwahl,项目名称:analytics,代码行数:11,代码来源:test_oauth_client.py


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