realdoug/omniauth-salesforce

solved: invalid_client_id

joshco opened this issue · 0 comments

I'd been pulling my hair out trying to get the demo app working, but kept getting invalid_client_id when omniauth-salesforce was trying to get the token.

I found a solution and figured I'd share it in case anyone is having the same problem. The answer for me is to pass client_options: { auth_scheme: :request_body } in the setup.

Here is the error as it shows up in the log:

192.168.10.1 - - [16/Jun/2018:06:13:15 +0000] "GET /auth/salesforce?display=page&immediate=false&scope=api%20id%20refresh_token%20web&client_id=3MVG-----------------------------------WgtSh4IEZ0a5a8UMpAD4eXbOKkvuQg4CFPnnnUajuqN8qlm HTTP/1.1" 302 564 0.1198
I, [2018-06-16T06:13:16.707526 #9400]  INFO -- omniauth: (salesforce) Callback phase initiated.
I, [2018-06-16T06:13:16.713188 #9400]  INFO -- : post https://login.salesforce.com/services/oauth2/token
D, [2018-06-16T06:13:16.714392 #9400] DEBUG -- request: User-Agent: "Faraday v0.14.0"
Content-Type: "application/x-www-form-urlencoded"
Authorization: "Basic M01WRzDkyNjQ0NDkxMDE0Mg=="
D, [2018-06-16T06:13:16.783984 #9400] DEBUG -- request: {"grant_type"=>"authorization_code",
 "code"=>
  "aPrxtfAlIdiLb5t.4xrQh8S75g9rsYmryjmxH==",
 :redirect_uri=>
  "https://joshco.vagrant.host/auth/salesforce/callback?display=page&code=aPrxtfAlIdiLb5t.4xrQh8S75g9rsYmryjmxHLxF917AhyRvGeijq7X08SzpnTe6eQ4t6DO6Jw%3D%3D&state=74e4645b1f5c1d710d6900eab7009b7a91d72bf58ef8bb20"}

I, [2018-06-16T06:13:17.099693 #9400]  INFO -- Status: 400
D, [2018-06-16T06:13:17.100525 #9400] DEBUG -- response: date: "Sat, 16 Jun 2018 06:13:15 GMT"
strict-transport-security: "max-age=31536000; includeSubDomains"
x-content-type-options: "nosniff"
x-xss-protection: "1; mode=block"
content-security-policy: "upgrade-insecure-requests"
cache-control: "no-cache,must-revalidate,max-age=0,no-store,private"
set-cookie: "BrowserId=-QOsW_rzQFaYe8fSPAmWng;Path=/;Domain=.salesforce.com;Expires=Wed, 15-Aug-2018 06:13:15 GMT;Max-Age=5184000, BrowserId=RkkN399PSRC8EVwzr029_A;Path=/;Domain=.salesforce.com;Expires=Wed, 15-Aug-2018 06:13:15 GMT;Max-Age=5184000"
expires: "Thu, 01 Jan 1970 00:00:00 GMT"
content-type: "application/json;charset=UTF-8"
transfer-encoding: "chunked"
connection: "close"
D, [2018-06-16T06:13:17.104153 #9400] DEBUG -- response: {"error":"invalid_client_id","error_description":"client identifier invalid"}
E, [2018-06-16T06:13:17.112424 #9400] ERROR -- omniauth: (salesforce) Authentication failure! invalid_credentials: OAuth2::Error, invalid_client_id: client identifier invalid
{"error":"invalid_client_id","error_description":"client identifier invalid"}

When I added the auth_scheme: :request_body, the successful logs are:

I, [2018-06-16T06:14:40.155643 #9473]  INFO -- omniauth: (salesforce) Callback phase initiated.
I, [2018-06-16T06:14:40.210200 #9473]  INFO -- : post https://login.salesforce.com/services/oauth2/token
D, [2018-06-16T06:14:40.216541 #9473] DEBUG -- request: User-Agent: "Faraday v0.14.0"
Content-Type: "application/x-www-form-urlencoded"
D, [2018-06-16T06:14:40.350320 #9473] DEBUG -- request: {"client_id"=>
  "3MVG9zlTNB8o8BA3XGOKkvuQg4CFPnnnUajuqN8qlm",
 "client_secret"=>"XXXXXXXXXXXXXXXXXXXXXXX",
 "grant_type"=>"authorization_code",
 "code"=>
  "aPrXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXmhUGHw==",
 :redirect_uri=>
  "https://joshco.vagrant.host/auth/salesforce/callback?display=page&code=aPrxtfXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXGHw%3D%3D&state=8841989b26456b04f94bd27f70d9fe500cf403e11e829253"}

I, [2018-06-16T06:14:40.709350 #9473]  INFO -- Status: 200

My builder config now looks like:

use OmniAuth::Builder do
    provider :salesforce, 
             ENV['SALESFORCE_KEY'], 
             ENV['SALESFORCE_SECRET'], {
                client_options: {
                    auth_scheme: :request_body
                }
   }
end