Skip to content

Commit

Permalink
Fix linkedin #6 #8
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Aug 24, 2018
1 parent d5b3454 commit cc15093
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions loginpass/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,42 @@
:license: AGPLv3+, see LICENSE for more details.
"""

import json
from authlib.specs.oidc import UserInfo
from ._core import OAuthBackend, map_profile_fields


def linkedin_compliance_fix(session):

def _token_response(resp):
data = json.loads(resp.text)
data['token_type'] = 'Bearer'
resp.json = lambda: data
return resp

session.register_compliance_hook('access_token_response', _token_response)


class LinkedIn(OAuthBackend):
OAUTH_TYPE = '2.0'
OAUTH_NAME = 'linkedin'
OAUTH_CONFIG = {
'api_base_url': 'https://api.linkedin.com/v1/',
'access_token_url': 'https://www.linkedin.com/oauth/v2/accessToken',
'authorize_url': 'https://www.linkedin.com/oauth/v2/authorization',
'client_kwargs': {'scope': 'r_basicprofile r_emailaddress'},
'client_kwargs': {
'scope': 'r_basicprofile r_emailaddress',
'token_endpoint_auth_method': 'client_secret_post',
},
'compliance_fix': linkedin_compliance_fix
}

def profile(self, **kwargs):
fields = [
'id', 'email-address', 'picture-url', 'public-profile-url',
'formatted-name', 'first-name', 'last-name', 'maiden-name',
]
url = 'people/~:({})'.format(','.join(fields))
url = 'people/~:({})?format=json'.format(','.join(fields))
resp = self.get(url, **kwargs)
resp.raise_for_status()
return UserInfo(map_profile_fields(resp.json(), {
Expand Down

0 comments on commit cc15093

Please sign in to comment.