Skip to content

Commit

Permalink
Merge branch 'linkedin-more-data' of keul/velruse into fix/pull-121
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Jun 27, 2013
2 parents 184546e + 58f8bd2 commit 57bd301
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
17 changes: 11 additions & 6 deletions example_test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ local_login_url = http://localhost:%(app_port)s/login
default_login_url = %(fqdn_login_url)s

test_providers =
# bitbucket
# facebook
# github
# bitbucket
# twitter
# google_hybrid
# google_oauth2
# yahoo
# linkedin
# live
# openid
# twitter
# yahoo

bitbucket.app =
bitbucket.login =
Expand All @@ -42,6 +43,9 @@ live.app =
live.login =
live.password =

linkedin.login =
linkedin.password =

openid.login =
openid.password =

Expand All @@ -57,15 +61,16 @@ yahoo.password =
use = call:tests.selenium.testapp:main

login_providers =
# bitbucket
# facebook
# github
# bitbucket
# twitter
# google_hybrid
# google_oauth2
# yahoo
# linkedin
# live
# openid
# twitter
# yahoo

# Bitbucket
velruse.bitbucket.consumer_key =
Expand Down
7 changes: 7 additions & 0 deletions tests/selenium/testapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,12 @@ def main(global_conf, **settings):
consumer_secret=settings['velruse.yahoo.consumer_secret'],
)

if 'linkedin' in providers:
config.include('velruse.providers.linkedin')
config.add_linkedin_login(
settings['velruse.linkedin.consumer_key'],
settings['velruse.linkedin.consumer_secret'],
)

config.scan(__name__)
return config.make_wsgi_app()
9 changes: 5 additions & 4 deletions tests/selenium/testapp/templates/login.mako
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@
${form('facebook', 'Login with Facebook',
scope='email,publish_stream,read_stream,create_event,offline_access')}
${form('github', 'Login with Github')}
${form('twitter', 'Login with Twitter')}
${form('bitbucket', 'Login with Bitbucket')}
${form('google_hybrid', 'Login with Google OpenID+OAuth',
use_popup='false',
openid_identifier='google.com')}
${form('google_oauth2', 'Login with Google OAuth2')}
${form('yahoo', 'Login with Yahoo',
oauth='true',
openid_identifier='yahoo.com')}
${form('linkedin', 'Login with Linkedin')}
${form('live', 'Login with Windows Live')}
${form('openid', 'Login with OpenID',
openid_identifier='myopenid.com')}
${form('twitter', 'Login with Twitter')}
${form('yahoo', 'Login with Yahoo',
oauth='true',
openid_identifier='yahoo.com')}

</body>
</html>
35 changes: 35 additions & 0 deletions tests/selenium/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,38 @@ def test_it(self):
profile = result['profile']
self.assertTrue('name' in profile)
self.assertTrue('accounts' in profile)

class TestLinkedin(ProviderTests, unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.require_provider('linkedin')
cls.login = config['linkedin.login']
cls.password = config['linkedin.password']
cls.login_url = find_login_url(config, 'linkedin.login_url')

def test_it(self):
browser.get(self.login_url)
self.assertEqual(browser.title, 'Auth Page')
browser.find_element_by_id('linkedin').submit()
self.assertEqual(browser.title, 'Authorize | LinkedIn')
form = browser.find_element_by_name('oauthAuthorizeForm')
login = form.find_element_by_id('session_key-oauthAuthorizeForm')
login.send_keys(self.login)
passwd = form.find_element_by_id('session_password-oauthAuthorizeForm')
passwd.send_keys(self.password)
form.find_element_by_name('authorize').submit()
result = WebDriverWait(browser, 2).until(
EC.presence_of_element_located((By.ID, 'result')))
self.assertEqual(browser.title, 'Result Page')
result = json.loads(result.text)
self.assertTrue('profile' in result)
self.assertTrue('credentials' in result)
profile = result['profile']
self.assertTrue('displayName' in profile)
self.assertTrue('accounts' in profile)
# BBB: Linkedin app must be enabled toshare e-mail
self.assertTrue('emails' in profile)
creds = result['credentials']
self.assertTrue('oauthAccessToken' in creds)
self.assertTrue('oauthAccessTokenSecret' in creds)
8 changes: 7 additions & 1 deletion velruse/providers/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def callback(self, request):
resource_owner_secret=creds['oauthAccessTokenSecret'])

profile_url = 'http://api.linkedin.com/v1/people/~'
profile_url += ':(first-name,last-name,id,date-of-birth,picture-url)'
profile_url += (':(first-name,last-name,id,date-of-birth,picture-url,'
'email-address)')
profile_url += '?format=json'

resp = requests.get(profile_url, auth=oauth)
Expand All @@ -148,6 +149,11 @@ def callback(self, request):
'familyName': data['lastName'],
'formatted': '%s %s' % (data['firstName'], data['lastName'])
}
if data.get('emailAddress'):
profile['emails'] = [{'value':data.get('emailAddress')}]
if data.get('pictureUrl'):
profile['photos'] = [{'value': data.get('pictureUrl')}]

profile['accounts'] = [{
'domain': 'linkedin.com',
'userid': data['id']
Expand Down

0 comments on commit 57bd301

Please sign in to comment.