pennersr / django-allauth

Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
https://allauth.org
MIT License
9.55k stars 3.04k forks source link

Linkedin OAuth 2.0 key error: missing id field in data #2138

Closed ronman closed 1 year ago

ronman commented 6 years ago

I'm using allauth 0.38.

No matter how I configure SOCIALACCOUNT_PROVIDERS, LinkedIn returns only the email, then complains about a missing id field. I noticed this was a problem fixed in Aug. 2018, has it returned?

Error is at: .local/lib/python3.5/site-packages/allauth/socialaccount/providers/linkedin_oauth2/provider.py in extract_uid at the line: return str(data['id'])

What's actually in data: data: {'emailAddress': 'myemail@example.com'}

Configuration:

SOCIALACCOUNT_PROVIDERS = {
  'linkedin': {
    'SCOPE': [ 'r_emailaddress', 'r_basicprofile', ],
    'PROFILE_FIELDS': [ 'id', 'first-name', 'last-name', 'email-address', 'picture-url', 'public-profile-url' ]
  }
}

Also tried:

SOCIALACCOUNT_PROVIDERS = {
  'linkedin': {
    'SCOPE': [ 'r_emailaddress', ],
    'PROFILE_FIELDS': [ 'id', 'email-address', ]
  }
}

And just in case, even though it's not mobile, tested with: 'HEADERS': { 'x-li-src': 'msdk' },

LinkedIn only returns email no matter what fields I indicate in the configuration.

I've never used Oauth1.0, so upgrading is not an issue. The Client_id and Secret were working earlier on this same project.

bennettrogers commented 5 years ago

I just ran into this as well after deploying my project to a new server. It turned out I had allauth v0.36.0 installed on the new instance (the version from my requirements.txt), but had updated my dev environment to 0.38.0 at some point. Updating the new deployment to 0.38.0 fixed the issue.

philippeluickx commented 5 years ago

I'm having the same issue, running on 0.38.0... I defined the settings as mentioned and still have the same problem. @ronman did you manage to fix this?

Edit: Just as a heads-up: for me the issue was actually not having the same scope defined in the frontend. Went smooth after defining that.

ronman commented 5 years ago

Can you expand on "not having the same scope defined" means, exactly?

I'm running allauth 38.0 on both development and production. The problem resolved itself and I don't know why. The only thing I can guess is that certain errors are cached by LinkedIn which eventually time themselves out. Though I changed the LinkedIn credentials with no success.

Please let us know if you find a better answer.

bastbnl commented 5 years ago

I believe the settings key for the oauth2 provider for LinkedIn should be linkedin_oauth2.

philippeluickx commented 5 years ago

@ronman I have a separate frontend (vue-auth) and backend (django allauth + django-rest-auth). I had defined the scope of my LinkedIn auth differently on both. Once both had the same scope defined, it worked well.

derek-adair commented 1 year ago

close this - old and likely a config issue.