當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。