Skip to content

Commit

Permalink
Merge pull request #397 from requests/linkedin-compliance-removal
Browse files Browse the repository at this point in the history
Linkedin compliance removal & LinkedIn Example update/fix
  • Loading branch information
jtroussard authored Feb 17, 2020
2 parents 29ba9af + feafa6d commit d75279c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 71 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ UNRELEASED
++++++++++

- Add initial support for OAuth Mutual TLS (draft-ietf-oauth-mtls)
- Removed outdated LinkedIn Compliance Fixes

v1.3.0 (6 November 2019)
++++++++++++++++++++++++
Expand Down
32 changes: 21 additions & 11 deletions docs/examples/linkedin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,41 @@ command line interactive example below.

.. code-block:: pycon
>>> # Imports
>>> import os
>>> from requests_oauthlib import OAuth2Session
>>> # Set environment variables
>>> os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
>>> # Credentials you get from registering a new application
>>> client_id = '<the id you get from linkedin>'
>>> client_secret = '<the secret you get from linkedin>'
>>> # OAuth endpoints given in the LinkedIn API documentation
>>> authorization_base_url = 'https://www.linkedin.com/uas/oauth2/authorization'
>>> token_url = 'https://www.linkedin.com/uas/oauth2/accessToken'
>>> # LinkedIn OAuth2 requests require scope and redirect_url parameters.
>>> # Ensure these values match the auth values in your LinkedIn App
>>> # (see auth tab on LinkedIn Developer page)
>>> scope = ['r_liteprofile']
>>> redirect_url = 'http://127.0.0.1'
>>> from requests_oauthlib import OAuth2Session
>>> from requests_oauthlib.compliance_fixes import linkedin_compliance_fix
>>> # OAuth endpoints given in the LinkedIn API documentation
>>> authorization_base_url = 'https://www.linkedin.com/oauth/v2/authorization'
>>> token_url = 'https://www.linkedin.com/oauth/v2/accessToken'
>>> linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1')
>>> linkedin = linkedin_compliance_fix(linkedin)
>>> linkedin = OAuth2Session(client_id, redirect_uri='http://127.0.0.1', scope=scope)
>>> # Redirect user to LinkedIn for authorization
>>> authorization_url, state = linkedin.authorization_url(authorization_base_url)
>>> print 'Please go here and authorize,', authorization_url
>>> print(f"Please go here and authorize: {authorization_url}")
>>> # Get the authorization verifier code from the callback url
>>> redirect_response = raw_input('Paste the full redirect URL here:')
>>> redirect_response = input('Paste the full redirect URL here:')
>>> # Fetch the access token
>>> linkedin.fetch_token(token_url, client_secret=client_secret,
... include_client_id=True,
... authorization_response=redirect_response)
>>> # Fetch a protected resource, i.e. user profile
>>> r = linkedin.get('https://api.linkedin.com/v1/people/~')
>>> print r.content
>>> r = linkedin.get('https://api.linkedin.com/v2/me')
>>> print(r.content)
1 change: 0 additions & 1 deletion requests_oauthlib/compliance_fixes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from .facebook import facebook_compliance_fix
from .fitbit import fitbit_compliance_fix
from .linkedin import linkedin_compliance_fix
from .slack import slack_compliance_fix
from .instagram import instagram_compliance_fix
from .mailchimp import mailchimp_compliance_fix
Expand Down
21 changes: 0 additions & 21 deletions requests_oauthlib/compliance_fixes/linkedin.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/test_compliance_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from requests_oauthlib import OAuth2Session
from requests_oauthlib.compliance_fixes import facebook_compliance_fix
from requests_oauthlib.compliance_fixes import fitbit_compliance_fix
from requests_oauthlib.compliance_fixes import linkedin_compliance_fix
from requests_oauthlib.compliance_fixes import mailchimp_compliance_fix
from requests_oauthlib.compliance_fixes import weibo_compliance_fix
from requests_oauthlib.compliance_fixes import slack_compliance_fix
Expand Down Expand Up @@ -99,43 +98,6 @@ def test_refresh_token(self):
self.assertEqual(token["refresh_token"], "refresh")


class LinkedInComplianceFixTest(TestCase):
def setUp(self):
mocker = requests_mock.Mocker()
mocker.post(
"https://www.linkedin.com/uas/oauth2/accessToken",
json={"access_token": "linkedin"},
)
mocker.post(
"https://api.linkedin.com/v1/people/~/shares",
status_code=201,
json={
"updateKey": "UPDATE-3346389-595113200",
"updateUrl": "https://www.linkedin.com/updates?discuss=abc&scope=xyz",
},
)
mocker.start()
self.addCleanup(mocker.stop)

linkedin = OAuth2Session("someclientid", redirect_uri="https://i.b")
self.session = linkedin_compliance_fix(linkedin)

def test_fetch_access_token(self):
token = self.session.fetch_token(
"https://www.linkedin.com/uas/oauth2/accessToken",
client_secret="someclientsecret",
authorization_response="https://i.b/?code=hello",
)
self.assertEqual(token, {"access_token": "linkedin", "token_type": "Bearer"})

def test_protected_request(self):
self.session.token = {"access_token": "dummy-access-token"}
response = self.session.post("https://api.linkedin.com/v1/people/~/shares")
url = response.request.url
query = parse_qs(urlparse(url).query)
self.assertEqual(query["oauth2_access_token"], ["dummy-access-token"])


class MailChimpComplianceFixTest(TestCase):
def setUp(self):
mocker = requests_mock.Mocker()
Expand Down

0 comments on commit d75279c

Please sign in to comment.