Uttam Sonani
Uttam Sonani

Reputation: 3

omniauth: (linkedin) Authentication failure! invalid_credentials

Request phase initiated.
Started GET "/users/auth/linkedin/callback?code=...&state=..." for 127.0.0.1 at 2022-09-14 20:50:20 +0200
D, [2022-09-14T20:50:20.537126 #37240] DEBUG -- omniauth: (linkedin) Callback phase initiated.
E, [2022-09-14T20:50:21.021252 #37240] ERROR -- omniauth: (linkedin) Authentication failure! invalid_credentials: OAuth2::Error, invalid_request: A required parameter "client_secret" is missing
{"error":"invalid_request","error_description":"A required parameter \"client_secret\" is missing"}
Processing by Users::OmniauthCallbacksController#failure as HTML
gem 'omniauth'
gem 'omniauth-linkedin-oauth2'

Upvotes: 0

Views: 814

Answers (3)

Paweł Gościcki
Paweł Gościcki

Reputation: 9594

As of 2023-08 a fix for this issue is to upgrade the omniauth-linkedin-oauth2 gem to the latest version (as https://github.com/decioferreira/omniauth-linkedin-oauth2/pull/71 has been merged and released as v1.0.1).

Upvotes: 0

Abdirahman Yusuf
Abdirahman Yusuf

Reputation: 26

I am new to rails and coding so I cannot offer any explanation to this issue and I was struggling for hours, I was using devise, so a workaround to this for me was to downgrade oauth2 version by adding:

gem 'oauth2', '~> 1.0'

in my Gemfile and running:

$ bundle install

My guess is this has something to do with JSON and I am not sure if it will affect devise functionality. The answer by Bhavesh Vadhvana also works.

Upvotes: 0

Bhavesh Vadhvana
Bhavesh Vadhvana

Reputation: 36

I can confirm that your fix does indeed work. Thank you! I'm adding it to my app to the config/initializers.rb as

 module OmniAuth
  module Strategies
    class LinkedIn < OmniAuth::Strategies::OAuth2
      def token_params
        super.tap do |params|
          params.client_secret = options.client_secret
        end
      end
    end
  end
end

Add this in your code

lib/strategies/linkedin.rb

And also this code in your devise.rb

require "strategies/linkedin"

Upvotes: 1

Related Questions