Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkedIn issue with multiple scopes #531

Closed
NebularNerd opened this issue Mar 5, 2024 · 1 comment
Closed

LinkedIn issue with multiple scopes #531

NebularNerd opened this issue Mar 5, 2024 · 1 comment

Comments

@NebularNerd
Copy link

NebularNerd commented Mar 5, 2024

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
Copy link
Author

Fixed it!

Two things were needed:

  • Make sure your scope= line contains all the scopes your access token allows. You may need to recreate your access token if like me you permitted a single scope previously.
  • Try adding the following above scope= (Reddit Thread):
import os
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant