本文整理汇总了Python中requests_oauthlib.OAuth1方法的典型用法代码示例。如果您正苦于以下问题:Python requests_oauthlib.OAuth1方法的具体用法?Python requests_oauthlib.OAuth1怎么用?Python requests_oauthlib.OAuth1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests_oauthlib
的用法示例。
在下文中一共展示了requests_oauthlib.OAuth1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dologin
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def dologin():
"""Attempt to login."""
if not (
'access_token_key' in session and
'access_token_secret' in session
):
raise NameError("No access keys")
access_token = AccessToken(
session['access_token_key'],
session['access_token_secret']
)
session['username'] = handshaker.identify(access_token)['username']
auth = OAuth1(
client_key=consumer_token.key,
client_secret=consumer_token.secret,
resource_owner_key=access_token.key,
resource_owner_secret=access_token.secret
)
return auth
示例2: _create_oauth_session
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def _create_oauth_session(self, oauth, timeout):
verify = self._options["verify"]
from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1
oauth = OAuth1(
oauth["consumer_key"],
rsa_key=oauth["key_cert"],
signature_method=SIGNATURE_RSA,
resource_owner_key=oauth["access_token"],
resource_owner_secret=oauth["access_token_secret"],
)
self._session = ResilientSession(timeout)
self._session.verify = verify
self._session.auth = oauth
示例3: request
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def request(self, method, url, **kwargs):
"""Build remote url request. Constructs necessary auth."""
user_token = kwargs.pop('token', self.token)
token, secret, _ = self.parse_raw_token(user_token)
callback = kwargs.pop('oauth_callback', None)
verifier = kwargs.get('data', {}).pop('oauth_verifier', None)
oauth = OAuth1(
resource_owner_key=token,
resource_owner_secret=secret,
client_key=self.consumer_key,
client_secret=self.consumer_secret,
verifier=verifier,
callback_uri=callback,
)
kwargs['auth'] = oauth
return super(OAuthProvider, self).request(method, url, **kwargs)
示例4: init_auth
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def init_auth(file):
(CONSUMER_KEY,
CONSUMER_SECRET,
OAUTH_TOKEN,
OAUTH_TOKEN_SECRET) = open(file, 'r').read().splitlines()
auth_obj = requests_oauthlib.OAuth1(
CONSUMER_KEY, CONSUMER_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
if verify_credentials(auth_obj):
print('Validated credentials OK')
return auth_obj
else:
print('Credentials validation failed')
sys.exit(1)
开发者ID:PacktPublishing,项目名称:Learning-Python-Networking-Second-Edition,代码行数:19,代码来源:twitter_connect.py
示例5: get_oauth
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def get_oauth():
filepath = "twitter.oauth"
with open(filepath, 'r'):
pass
config = configparser.SafeConfigParser()
config.read(filepath)
params = ['consumer_key', 'consumer_secret', 'oauth_token', 'oauth_token_secret']
if 'oauth' not in config.sections():
raise RuntimeError("Bad oauth file format %s, section missing: %s" % (filepath, 'oauth'))
oauth_config = dict(config.items('oauth'))
for param in params:
if param not in oauth_config:
raise RuntimeError("Bad oauth file format %s, not found param: %s" % (filepath, param))
oauth = OAuth1(oauth_config['consumer_key'],
client_secret=oauth_config['consumer_secret'],
resource_owner_key=oauth_config['oauth_token'],
resource_owner_secret=oauth_config['oauth_token_secret'])
return oauth
示例6: get_profile_data
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def get_profile_data(resource_owner_key, resource_owner_secret):
oauth = OAuth1(
settings.SOCIAL_AUTH_LINKEDIN_KEY,
client_secret=settings.SOCIAL_AUTH_LINKEDIN_SECRET,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret
)
linkedin_api_endpoint = LINKEDIN_PROFILE_API_BASE_URL % ','.join(LINKEDIN_PROFILE_FIELDS)
response = requests.get(
url=linkedin_api_endpoint,
auth=oauth
)
# TODO: uncomment to purposely raise Exception and see format
#raise Exception(response.text)
linkedin_profile_data = json.loads(response.text)
return linkedin_profile_data
示例7: send
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def send(self, message, fail_silently=False, options=None):
payload = {
"status": message
}
self._set_payload_from_options(payload, options, "twitter", [
"in_reply_to_status_id", "possibly_sensitive", "lat", "long",
"place_id", "display_coordinates", "trim_user", "media_ids"])
auth = OAuth1(self.api_key, self.api_secret, self.access_token,
self.access_token_secret)
try:
response = requests.post(self.url, auth=auth, data=payload)
if response.status_code != requests.codes.ok:
raise HttpError(response.status_code, response.text)
except Exception:
if not fail_silently:
raise
示例8: get_twitter_request_token
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def get_twitter_request_token():
request_token_url = 'https://api.twitter.com/oauth/request_token'
oauth = OAuth1(
os.getenv('TWITTER_CONSUMER_KEY'),
client_secret=os.getenv('TWITTER_CONSUMER_SECRET'),
callback_uri=request.args.get('redirectUri')
)
r = requests.post(request_token_url, auth=oauth)
oauth_token_dict = dict(parse_qsl(r.text))
return jsonify(oauth_token_dict)
##########
# admin
示例9: unauthorized_token_request
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def unauthorized_token_request(self):
"""Return request for unauthorized token (first stage)"""
params = self.request_token_extra_arguments()
params.update(self.get_scope_argument())
key, secret = self.get_key_and_secret()
# decoding='utf-8' produces errors with python-requests on Python3
# since the final URL will be of type bytes
decoding = None if six.PY3 else 'utf-8'
state = self.get_or_create_state()
auth = OAuth1(
key,
secret,
callback_uri=self.get_redirect_uri(state),
decoding=decoding,
signature_method=SIGNATURE_HMAC,
signature_type=SIGNATURE_TYPE_QUERY
)
url = self.REQUEST_TOKEN_URL + '?' + urlencode(params)
url, _, _ = auth.client.sign(url)
return url
示例10: oauth_auth
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def oauth_auth(self, token=None, oauth_verifier=None):
key, secret = self.get_key_and_secret()
oauth_verifier = oauth_verifier or self.data.get('oauth_verifier')
token = token or {}
# decoding='utf-8' produces errors with python-requests on Python3
# since the final URL will be of type bytes
decoding = None if six.PY3 else 'utf-8'
state = self.get_or_create_state()
return OAuth1(key, secret,
resource_owner_key=token.get('oauth_token'),
resource_owner_secret=token.get('oauth_token_secret'),
callback_uri=self.get_redirect_uri(state),
verifier=oauth_verifier,
signature_method=SIGNATURE_HMAC,
signature_type=SIGNATURE_TYPE_QUERY,
decoding=decoding)
示例11: clean_oauth_auth
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def clean_oauth_auth(self, access_token):
"""Override of oauth_auth since Xing doesn't like callback_uri
and oauth_verifier on authenticated API calls"""
key, secret = self.get_key_and_secret()
resource_owner_key = access_token.get('oauth_token')
resource_owner_secret = access_token.get('oauth_token_secret')
if not resource_owner_key:
raise AuthTokenError(self, 'Missing oauth_token')
if not resource_owner_secret:
raise AuthTokenError(self, 'Missing oauth_token_secret')
# decoding='utf-8' produces errors with python-requests on Python3
# since the final URL will be of type bytes
decoding = None if six.PY3 else 'utf-8'
return OAuth1(key, secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret,
signature_type=SIGNATURE_TYPE_AUTH_HEADER,
decoding=decoding)
示例12: unauthorized_token
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def unauthorized_token(self):
"""Return request for unauthorized token (first stage)"""
params = self.request_token_extra_arguments()
params.update(self.get_scope_argument())
key, secret = self.get_key_and_secret()
# decoding='utf-8' produces errors with python-requests on Python3
# since the final URL will be of type bytes
decoding = None if six.PY3 else 'utf-8'
state = self.get_or_create_state()
response = self.request(
self.REQUEST_TOKEN_URL,
params=params,
auth=OAuth1(key, secret, callback_uri=self.get_redirect_uri(state),
decoding=decoding),
method=self.REQUEST_TOKEN_METHOD
)
content = response.content
if response.encoding or response.apparent_encoding:
content = content.decode(response.encoding or
response.apparent_encoding)
else:
content = response.content.decode()
return content
示例13: oauth_auth
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def oauth_auth(self, token=None, oauth_verifier=None,
signature_type=SIGNATURE_TYPE_AUTH_HEADER):
key, secret = self.get_key_and_secret()
oauth_verifier = oauth_verifier or self.data.get('oauth_verifier')
token = token or {}
# decoding='utf-8' produces errors with python-requests on Python3
# since the final URL will be of type bytes
decoding = None if six.PY3 else 'utf-8'
state = self.get_or_create_state()
return OAuth1(key, secret,
resource_owner_key=None,
resource_owner_secret=None,
callback_uri=self.get_redirect_uri(state),
verifier=oauth_verifier,
signature_type=signature_type,
decoding=decoding)
示例14: make_request
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def make_request(self, method, url, data=None, params=None, headers=None,
timeout=60):
if headers is None:
headers = {'x-li-format': 'json', 'Content-Type': 'application/json'}
else:
headers.update({'x-li-format': 'json', 'Content-Type': 'application/json'})
if params is None:
params = {}
kw = dict(data=data, params=params,
headers=headers, timeout=timeout)
if isinstance(self.authentication, LinkedInDeveloperAuthentication):
# Let requests_oauthlib.OAuth1 do *all* of the work here
auth = OAuth1(self.authentication.consumer_key, self.authentication.consumer_secret,
self.authentication.user_token, self.authentication.user_secret)
kw.update({'auth': auth})
else:
params.update({'oauth2_access_token': self.authentication.token.access_token})
return requests.request(method.upper(), url, **kw)
示例15: get_xauth_access_token
# 需要导入模块: import requests_oauthlib [as 别名]
# 或者: from requests_oauthlib import OAuth1 [as 别名]
def get_xauth_access_token(self, username, password):
"""
Get an access token from an username and password combination.
In order to get this working you need to create an app at
http://twitter.com/apps, after that send a mail to api@twitter.com
and request activation of xAuth for it.
"""
try:
url = self._get_oauth_url('access_token')
oauth = OAuth1(self.consumer_key,
client_secret=self.consumer_secret)
r = requests.post(url=url,
auth=oauth,
headers={'x_auth_mode': 'client_auth',
'x_auth_username': username,
'x_auth_password': password})
credentials = parse_qs(r.content)
return credentials.get('oauth_token')[0], credentials.get('oauth_token_secret')[0]
except Exception as e:
raise TweepError(e)