Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linkedin_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '0.9.5'
__version__ = '0.9.6'
VERSION = tuple(map(int, __version__.split('.')))
13 changes: 13 additions & 0 deletions linkedin_v2/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
EMAIL_ADDRESS='r_emailaddress',
NETWORK='r_network',
CONTACT_INFO='r_contactinfo',
MEMBER_SOCIAL='w_member_social',
NETWORK_UPDATES='rw_nus',
GROUPS='rw_groups',
MESSAGES='w_messages')
Expand Down Expand Up @@ -85,6 +86,7 @@ class LinkedInAuthentication(object):
"""
AUTHORIZATION_URL = 'https://www.linkedin.com/uas/oauth2/authorization'
ACCESS_TOKEN_URL = 'https://www.linkedin.com/uas/oauth2/accessToken'
INTROSPECT_TOKEN_URL = 'https://www.linkedin.com/oauth/v2/introspectToken'

def __init__(self, key, secret, redirect_uri=None, permissions=None):
self.key = key
Expand Down Expand Up @@ -167,6 +169,17 @@ def refresh_access_token(self, refresh_token, timeout=TIMEOUT):
self.token = self._get_token_from_response(response)
return self.token

def introspect_token(self, access_token, timeout=TIMEOUT):
qd = {
INTROSPECT_TOKEN_KEY: access_token,
'client_id': self.key,
'client_secret': self.secret
}
response = requests.post(self.INTROSPECT_TOKEN_URL, data=qd, timeout=timeout)
raise_for_error(response)

return response.json()


class LinkedInSelector(object):
@classmethod
Expand Down
1 change: 1 addition & 0 deletions linkedin_v2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ACCESS_TOKEN_KEY = 'access_token'
EXPIRES_IN_KEY = 'expires_in'
REFRESH_TOKEN_KEY = 'refresh_token'
INTROSPECT_TOKEN_KEY = 'token'
REFRESH_TOKEN_EXPIRES_IN_KEY = 'refresh_token_expires_in'

AccessToken = collections.namedtuple('AccessToken',
Expand Down
7 changes: 5 additions & 2 deletions linkedin_v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ def raise_for_error(response):
return
response = response.json()
if ('error' in response) or ('errorCode' in response):
message = '%s: %s' % (response.get('error', str(error)),
response.get('message', 'Unknown Error'))

error_description = response.get('error_description') or response.get('message', 'Unknown Error')
error_name = response.get('error')
error_code = response.get('status')

message = '%s: %s' % (error_name, error_description)
ex = get_exception_for_error_code(error_code)
raise ex(message)
else:
Expand Down