Skip to content

Commit

Permalink
update yahoo to use oauthlib
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Jun 14, 2013
1 parent e8a2d22 commit 3194ca2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
36 changes: 23 additions & 13 deletions tests/selenium/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,29 +285,39 @@ def test_it(self):
browser.get(self.login_url)
self.assertEqual(browser.title, 'Auth Page')
browser.find_element_by_id('yahoo').submit()
WebDriverWait(browser, 10).until(
lambda driver: driver.find_element_by_id('username'))
WebDriverWait(browser, 2).until(
EC.presence_of_element_located((By.ID, 'username')))
self.assertEqual(browser.title, 'Sign in to Yahoo!')
login = browser.find_element_by_id('username')
login.send_keys(self.login)
passwd = browser.find_element_by_id('passwd')
passwd.send_keys(self.password)
passwd.submit()
def _wait_for_alert(driver):
# there may be a captcha here, possibly wait for user input???
find_alert = EC.alert_is_present()
find_auth_agree = EC.presence_of_element_located((By.ID, 'agree'))
WebDriverWait(browser, 2).until(
lambda driver: find_alert(driver) or find_auth_agree(driver))
auth_agree = browser.find_element_by_id('agree')
if auth_agree:
auth_agree.click()
alert = WebDriverWait(browser, 2).until(EC.alert_is_present())
else:
alert = browser.switch_to_alert()
try:
alert.accept()
except:
pass
return driver.find_element_by_id('result')
WebDriverWait(browser, 10).until(_wait_for_alert)
alert.accept()
result = WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.ID, 'result')))
self.assertEqual(browser.title, 'Result Page')
result = browser.find_element_by_id('result').text
result = json.loads(result)
result = json.loads(result.text)
self.assertTrue('profile' in result)
self.assertTrue('credentials' in result)
self.assertTrue('displayName' in result['profile'])
self.assertTrue('accounts' in result['profile'])
profile = result['profile']
self.assertTrue('displayName' in profile)
self.assertTrue('accounts' in profile)
self.assertTrue('emails' in profile)
creds = result['credentials']
self.assertTrue('oauthAccessToken' in creds)
self.assertTrue('oauthAccessTokenSecret' in creds)

class TestWindowsLive(ProviderTests, unittest.TestCase):

Expand Down
35 changes: 20 additions & 15 deletions velruse/providers/yahoo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import absolute_import

import oauth2 as oauth
from openid.extensions import ax

import requests
from requests_oauthlib import OAuth1

from pyramid.security import NO_PERMISSION_REQUIRED

from ..api import register_provider
from ..compat import parse_qs
from ..compat import parse_qsl

from .oid_extensions import OAuthRequest
from .openid import (
Expand Down Expand Up @@ -94,16 +96,19 @@ def _update_authrequest(self, request, authrequest):
authrequest.addExtension(oauth_request)

def _get_access_token(self, request_token):
consumer = oauth.Consumer(key=self.oauth_key, secret=self.oauth_secret)
token = oauth.Token(key=request_token, secret='')
client = oauth.Client(consumer, token)
resp, content = client.request(YAHOO_OAUTH, "POST")
if resp['status'] != '200':
log.error("OAuth token validation failed. Status: %s, Content: %s",
resp['status'], content)
return

access_token = dict(parse_qs(content))

return {'oauthAccessToken': access_token['oauth_token'],
'oauthAccessTokenSecret': access_token['oauth_token_secret']}
oauth = OAuth1(
self.oauth_key,
client_secret=self.oauth_secret,
resource_owner_key=request_token)

resp = requests.post(YAHOO_OAUTH, auth=oauth)
if resp.status_code != 200:
log.error(
'OAuth token validation failed. Status: %d, Content: %s',
resp.status_code, resp.content)
else:
access_token = dict(parse_qsl(resp.content))
return {
'oauthAccessToken': access_token['oauth_token'],
'oauthAccessTokenSecret': access_token['oauth_token_secret'],
}

0 comments on commit 3194ca2

Please sign in to comment.