本文整理汇总了Python中requests_oauthlib.OAuth2方法的典型用法代码示例。如果您正苦于以下问题:Python requests_oauthlib.OAuth2方法的具体用法?Python requests_oauthlib.OAuth2怎么用?Python requests_oauthlib.OAuth2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests_oauthlib
的用法示例。
在下文中一共展示了requests_oauthlib.OAuth2方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SetCredentials
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def SetCredentials(self,
consumer_key,
consumer_secret,
access_token_key=None,
access_token_secret=None,
application_only_auth=False):
"""Set the consumer_key and consumer_secret for this instance
Args:
consumer_key:
The consumer_key of the twitter account.
consumer_secret:
The consumer_secret for the twitter account.
access_token_key:
The oAuth access token key value you retrieved
from running get_access_token.py.
access_token_secret:
The oAuth access token's secret, also retrieved
from the get_access_token.py run.
application_only_auth:
Whether to generate a bearer token and use Application-Only Auth
"""
self._consumer_key = consumer_key
self._consumer_secret = consumer_secret
self._access_token_key = access_token_key
self._access_token_secret = access_token_secret
if application_only_auth:
self._bearer_token = self.GetAppOnlyAuthToken(consumer_key, consumer_secret)
self.__auth = OAuth2(token=self._bearer_token)
else:
auth_list = [consumer_key, consumer_secret,
access_token_key, access_token_secret]
if all(auth_list):
self.__auth = OAuth1(consumer_key, consumer_secret,
access_token_key, access_token_secret)
self._config = None
示例2: signed_session
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def signed_session(self, session=None):
# type: (Optional[requests.Session]) -> requests.Session
"""Create requests session with any required auth headers applied.
If a session object is provided, configure it directly. Otherwise,
create a new session and return it.
:param session: The session to configure for authentication
:type session: requests.Session
:rtype: requests.Session
"""
session = session or requests.Session() # Don't call super on purpose, let's "auth" manage the headers.
session.auth = oauth.OAuth2(self.id, token=self.token)
return session
示例3: get_request_kwargs
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def get_request_kwargs(self, api_params, *args, **kwargs):
params = super(FacebookClientAdapter, self).get_request_kwargs(
api_params, *args, **kwargs)
params['auth'] = OAuth2(
api_params.get('client_id'), token={
'access_token': api_params.get('access_token'),
'token_type': 'Bearer'})
return params
示例4: github_login_behavior
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def github_login_behavior():
url = github_apis.auth_user()
auth = OAuth2(client_id=client_id, token=session['oauth_user_token'])
res = requests.get(url, auth=auth)
if res.status_code != 200:
msg = 'GitHub authorization failed'
url = url_for('accounts.register')
flash(msg, 'danger')
return redirect(url)
github_user = res.json()
username = github_user.get('login')
# email = github_user.get('email')
# github_url = github_user.get('html_url')
# github_avatar_url = github_user.get('avatar_url')
try:
user = models.User.objects.get(github_username=username)
except models.User.DoesNotExist:
msg = 'Please register first'
flash(msg, 'danger')
return redirect(url_for('accounts.register'))
login_user(user)
user.last_login = datetime.datetime.now
user.save()
url = url_for('main.index')
return redirect(url)
示例5: github_link_account_behavior
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def github_link_account_behavior():
url = github_apis.auth_user()
auth = OAuth2(client_id=client_id, token=session['oauth_user_token'])
res = requests.get(url, auth=auth)
if res.status_code != 200:
msg = 'GitHub authorization failed'
flash(msg, 'danger')
return redirect(url_for('main.index'))
github_user = res.json()
username = github_user.get('login')
email = github_user.get('email')
github_url = github_user.get('html_url')
github_avatar_url = github_user.get('avatar_url')
if len(models.User.objects.filter(github_username=username)) > 0:
msg = 'This GitHub account({0}) has been binded to another user'.format(username)
flash(msg, 'danger')
return redirect(url_for('main.index'))
if not current_user.avatar_url:
avatar_name = 'github_avatar_{0}.jpeg'.format(username)
avatar_url = qiniu_fetch_img(github_avatar_url, avatar_name)
current_user.avatar_url = avatar_url
current_user.github_username = username
current_user.github = github_url
current_user.save()
return redirect(url_for('main.index'))
示例6: github_auth_user_behavior
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth2 [as 别名]
def github_auth_user_behavior():
url = github_apis.auth_user()
auth = OAuth2(client_id=client_id, token=session['oauth_user_token'])
res = requests.get(url, auth=auth)
if res.status_code != 200:
msg = 'GitHub authorization failed'
url = url_for('accounts.register')
flash(msg, 'danger')
return False
return True