requests / requests-oauthlib

OAuthlib support for Python-Requests!
https://requests-oauthlib.readthedocs.org/
ISC License
1.71k stars 421 forks source link

LinkedIn issue with multiple scopes #531

Closed NebularNerd closed 4 months ago

NebularNerd commented 4 months ago

I'm close to getting posts working on my Company page. I have the everything working in terms of Auth-ing #519 (It taken me since then to finally beat LinkedIn into submission and activate my app). However, I'm having issues setting all the scopes I need.

I get the Auth login prompt appear for me to Auth the app, but after pressing Allow I get an error in the workflow with:

Warning

Scope has changed from "w_organization_social w_organization_social_feed w_member_social_feed w_member_social" to "w_member_social,w_member_social_feed,w_organization_social,w_organization_social_feed".
Traceback (most recent call last):

  File "/nano-py/pipedream/worker.py", line 137, in execute
    user_retval = handler(pd)
                  ^^^^^^^^^^^

  File "/tmp/__pdg__/dist/code/09affe3ef9af79ff9e8512968c7fa18071f314e61ceeb78977be274cdfd4e81b/code.py", line 84, in handler
    token = linkedin.fetch_token(token_url, client_secret=vars["client_secret"],
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/tmp/__pdg__/dist/python/requests_oauthlib/oauth2_session.py", line 366, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)

  File "/tmp/__pdg__/dist/python/oauthlib/oauth2/rfc6749/clients/base.py", line 427, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/tmp/__pdg__/dist/python/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
    validate_token_parameters(params)

  File "/tmp/__pdg__/dist/python/oauthlib/oauth2/rfc6749/parameters.py", line 471, in validate_token_parameters
    raise w

Warning: Scope has changed from "w_member_social w_organization_social_feed w_organization_social w_member_social_feed" to "w_member_social,w_member_social_feed,w_organization_social,w_organization_social_feed".

I have scopes as follows (heavily abbreviated code):

scope = ['w_member_social','w_organization_social','w_organization_social_feed','w_member_social_feed']
redirect_url = 'https://thatwouldbea.secret'

# 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(vars["client_id"], redirect_uri=redirect_url, scope=scope) 

# Redirect user to LinkedIn for authorization
authorization_url, state = linkedin.authorization_url(authorization_base_url)
print (authorization_url)

If I just have scope = ['w_member_social'] that's all find and dandy. Looking at the docs, I appear to be using the correct format so not sure what the issue might be. Can anyone shed some light on what might be going on?

NebularNerd commented 4 months ago

Fixed it!

Two things were needed: