简体   繁体   中英

Linkedin Omniauth gem 'omniauth-linkedin-oauth2' giving Authentication failure! invalid_credentials: OAuth2::Error

I have an application running with successful Google and Facebook omniauthentication running. I want to add Linkedin Login too with omniauth. All seems to fine until I request the email address by adding :scope => 'r_emailaddress' to the line

devise.rb

  config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'], :scope => 'r_emailaddress', :fields => ['email', 'id', 'first-name', 'last-name']

All seems to be correct if I removed the r_emailaddress and add any other scope like r_liteprofile as

  config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'], :scope => 'r_liteprofile', :fields => ['email', 'id', 'first-name', 'last-name']

Gemfile

gem 'omniauth-linkedin-oauth2'

The error is coming up in the backend and in the front end after successfully putting all the credentials on the Linkedin page, the app is redirecting to the home page and not giving any error in the UI.

The error it's throwing in the logs is

ERROR -- omniauth: (linkedin) Authentication failure! invalid_credentials: OAuth2::Error, : 
{"serviceErrorCode":100,"message":"Not enough permissions to access: GET /me","status":403}

It would be great if anyone can help me in this matter.

Remove scope and fields both and try this:

config.omniauth :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM