本文整理汇总了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')
示例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.')
示例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.")
示例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
示例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 )
示例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)
示例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)
示例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())
示例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)
示例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
示例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'))
示例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
示例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)
示例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())
示例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)