Rails Omniauth for Linkedin not working
Asked Answered
V

1

6

I'm trying to get the Linkedin access token by Omniauth, using Devise, Omniauth and omniauth-linkedin-oauth-2. Either with facebook and twitter, I can get the access token, but when I try it with linkedin, I'm getting the following error in the omniauth callback:

ERROR -- omniauth: (linkedin) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired
{"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired","error":"invalid_request"}

The linkedin app id and secret authentication is working, as I'm getting the callback on omniauth, the thing is I can't realise what the problem is here.

Devise config below:

  config.omniauth :linkedin, ENV['LINKEDIN_APP_ID'], ENV['LINKEDIN_APP_SECRET']

Any ideas on what could be happening?

Vicechancellor answered 28/11, 2015 at 19:31 Comment(8)
Are you trying this in development or production? In my experience you need to have two Linkedin apps - one that has the exact localhost:portnumber for development and another for production use.Cuprum
In development. I have http://localhost:3000/users/auth/linkedin/callback in the Authorized Redirect URLs of the Linkedin appVicechancellor
I had trouble with that - have a look at the docs. I think it was something about it being comma-separated versus linebreak-separated.Cuprum
Just looked and it's comma-separated, but the UI makes you think you should put each one on a separate line. Is that it?Cuprum
@Cuprum I updated the question with comma-separated, I tried it, and I'm getting the same failure message :(Vicechancellor
I had tons of trouble with attending.io on this. Are you using omniauth-linkedin-oauth2? Looking at my code I had to do this: config.omniauth :linkedin, ENV["LINKEDIN_KEY"], ENV["LINKEDIN_SECRET"], :scope => 'r_basicprofile r_emailaddress', :fields => ['id', 'email-address', 'first-name', 'last-name', 'headline', 'industry', 'picture-url', 'public-profile-url']Cuprum
thanks for the quick reply. Yes, I'm using omniauth-linkedin-oauth2 and I tried with your config line and still no luck...Vicechancellor
try puts-ing your config just to make sure it really is set?Cuprum
F
10

I had the same problem and I found a way to resolve that. In your Gemfile put this:

#Contains a generic OAuth2 strategy for OmniAuth
gem 'omniauth-oauth2', '~> 1.3.1'

And finally do:

bundle update

I think it should work.

More info in: https://github.com/intridea/omniauth-oauth2/issues/81

Fibster answered 15/12, 2015 at 16:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.