Skip to content

Commit

Permalink
Made LinkedIn profile fields configurable (closes #397)
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Oct 16, 2013
1 parent 67bf8f3 commit 66c2045
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
16 changes: 11 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ settings.py::
'allauth',
'allauth.account',
'allauth.socialaccount',
# ... include the providers you want to enable:
# ... include the providers you want to enable:
'allauth.socialaccount.providers.bitly',
'allauth.socialaccount.providers.dropbox',
'allauth.socialaccount.providers.facebook',
Expand Down Expand Up @@ -577,7 +577,7 @@ The following Facebook settings are available::
SOCIALACCOUNT_PROVIDERS = \
{ 'facebook':
{ 'SCOPE': ['email', 'publish_stream'],
'AUTH_PARAMS': { 'auth_type': 'reauthenticate' },
'AUTH_PARAMS': { 'auth_type': 'reauthenticate' },
'METHOD': 'oauth2' ,
'LOCALE_FUNC': 'path.to.callable'} }

Expand Down Expand Up @@ -637,11 +637,17 @@ The LinkedIn provider is OAuth based. Register your LinkedIn app over
at `https://www.linkedin.com/secure/developer?newapp=`. Leave the
OAuth redirect URL empty.

You can specify the scope to use as follows::
You can specify the scope and fields to fetch as follows::

SOCIALACCOUNT_PROVIDERS = \
{ 'linkedin':
{ 'SCOPE': ['r_emailaddress'] } }
{'linkedin':
{'SCOPE': ['r_emailaddress'],
'PROFILE_FIELDS: ['id',
'first-name',
'last-name',
'email-address',
'picture-url',
'public-profile-url']}}

By default, `r_emailaddress` scope is required depending on whether or
not `SOCIALACCOUNT_QUERY_EMAIL` is enabled.
Expand Down
11 changes: 11 additions & 0 deletions allauth/socialaccount/providers/linkedin/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def get_default_scope(self):
scope.append('r_emailaddress')
return scope

def get_profile_fields(self):
default_fields = ['id',
'first-name',
'last-name',
'email-address',
'picture-url',
'public-profile-url']
fields = self.get_settings().get('PROFILE_FIELDS',
default_fields)
return fields

def extract_uid(self, data):
return data['id']

Expand Down
12 changes: 5 additions & 7 deletions allauth/socialaccount/providers/linkedin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.utils import six

from allauth.socialaccount import providers
from allauth.socialaccount.providers.oauth.client import OAuth
from allauth.socialaccount.providers.oauth.views import (OAuthAdapter,
OAuthLoginView,
Expand All @@ -13,15 +14,12 @@

class LinkedInAPI(OAuth):
url = 'https://api.linkedin.com/v1/people/~'
fields = ['id',
'first-name',
'last-name',
'email-address',
'picture-url',
'public-profile-url']

def get_user_info(self):
url = self.url + ':(%s)' % ','.join(self.fields)
fields = providers.registry \
.by_id(LinkedInProvider.id) \
.get_profile_fields()
url = self.url + ':(%s)' % ','.join(fields)
raw_xml = self.query(url)
if not six.PY3:
raw_xml = raw_xml.encode('utf8')
Expand Down

0 comments on commit 66c2045

Please sign in to comment.