# Unable to authenticate you - 500 or 400 error

**URL:** <https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455>\
**Category:** Help me!\
**Created:** [October 5, 2021, 6:46am UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455 "2021-10-05T06:46:28Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 6:46am UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/1 "2021-10-05T06:46:28Z")

</div>

## Expected behavior

Able to open forest in production.

## Actual behavior

1st ERROR (without client id)

 ![Screenshot 2021-10-05 at 09.59.36](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/5ffa829af5fd8fcefbcd56331807ab6d4dff3f89.jpeg)

2nd error (with client id)

 ![Screenshot 2021-10-05 at 13.48.40](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2db8306470b76a8a25f183a9518592b3e9b5181f.jpeg)

What is the current behavior?  
Hello everyone!

I am using Rails 5.1, ruby 2.7.4 .

- I tried restarting server.
- Cleared cache.
- udpated CORS cofigs in application.rb , no it looks like this:

````javascript
 config.load_defaults 5.1

    null_regex = Regexp.new(/\Anull\z/)
    config.middleware.insert_before 0, Rack::Cors do
      allow do
        hostnames = [null_regex, 'localhost:3000', 'app.forestadmin.com', 'localhost:3001']
        hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']
        origins hostnames
        resource '*',
          headers: :any,
          methods: :any,
          expose: ['Content-Disposition'],
          credentials: true
      end
    end```

* Added forest URL to secrets.yml and initializer
forest_liana.rb: 

````

ForestLiana.env\_secret = Rails.application.secrets.forest\_env\_secret  
ForestLiana.auth\_secret = Rails.application.secrets.forest\_auth\_secret  
ForestLiana.application\_url = Rails.application.secrets.forest\_application\_url

```javascript
in secrets.yml

```

forest\_application\_url: \<%= ENV[“APPLICATION\_URL”] %\>

```javascript

* Added Http initializer

```

require ‘httpclient’

class HTTPClient  
alias original\_initialize initialize

def initialize(\*args, &block)  
original\_initialize(\*args, &block)  
# Force use of the default system CA certs (instead of the 6 year old bundled ones)  
@session\_manager&.ssl\_config&.set\_default\_paths  
end  
end

```javascript

Until now I had 500 error when inspecting the code.

* So i decided to add client_id . I added it to secters.yml and to forest_liana.rb .

```

ForestLiana.env\_secret = Rails.application.secrets.forest\_env\_secret  
ForestLiana.auth\_secret = Rails.application.secrets.forest\_auth\_secret  
ForestLiana.application\_url = Rails.application.secrets.forest\_application\_url  
ForestLiana.forest\_client\_id = Rails.application.secrets.forest\_client\_id

```javascript
So now I have GET https://www.gravatar.com/avatar/e30ed105537f357ef10afcf0cab74e78?s=80&d=404 404

&&

chunk.7.3063f605868b6fe645c9.js:353 GET https://api.forestadmin.com/oidc/auth?client_id=eyJra ****** 400 (Bad Request)

Please let me know what else can be done?

Please include any relevant log snippets, if necessary.

## Context

Please provide any relevant information about your setup.
Rails 5.1 , ruby 2.7.4
* Package Version: gem is updated to 7.2.2 
* Express Version:
* Sequelize Version:
* Database Dialect: postgres
* Database Version: 
* Project Name: Spare Leash
```

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 8:49am UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/2 "2021-10-05T08:49:43Z")

</div>

Hello @kittinson,

I have few question in order to help you:

- Did your production environment worked before?
- When this error first came?
- Did do you do something that could broke your production environment?
- Can you share the response error you got in your /forest/authentication call

If you were not using a **clientId** before then you do not need to use it.

Also maybe you could share the logs you get on your server side, it would help to debug you

Kind regards,  
Louis

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 12:15pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/3 "2021-10-05T12:15:43Z")

</div>

Hello @anon16419211 !

- Did your production environment worked before?

> Yes, we have been happily using Forest for past 3 years.

- When this error first came?

> Sept 30th

- Did do you do something that could broke your production environment?

> no updates were made these days, the day problem happened. Oct 2nd we updated ruby from 2.5.1 to 2.7.4 and letsencrypt gem, as we were also using it and some of dependencies stopped working.

- Can you share the response error you got in your /forest/authentication call  
for 500 witour clint\_id  
 ![forest-error](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/fadda58cf7762176b6faaa5fb6fba0df6de5772c.jpeg)  
with client\_id  
 ![Screenshot 2021-10-05 at 19.19.09](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/59aa2a12f37ac09048239b2446bd45c480ef32c9.png)  
 ![Screenshot 2021-10-05 at 19.22.15](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/a9b598d2c5e10efce70ff01a53fbdc6e897f45da.png)  
 ![Screenshot 2021-10-05 at 19.23.21](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/b6f5b815a9d63ff317d0ff280ab70ad457d01c7c.png)

and another 404

 ![Screenshot 2021-10-05 at 19.21.08](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8726f445c29d29e4d7aec39a8ef29b59ce146a6b.png)

If you were not using a **clientId** before then you do not need to use it.

> Thank you , then I will delete it.

I would really appreciate help! Let me know if need any more info from my end.

Thank you!

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 12:25pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/4 "2021-10-05T12:25:30Z")

</div>

@kittinson

Could you eventually try to do a `curl https://api.forestadmin.com` from your OS (or docker container if you are using one)?  
If you are experiencing the SSL issue, you could either

- try to upgrade your docker base image to a newer one, or
- try to manually invalidate and update the certificate causing the issue via

```javascript
rm /usr/share/ca-certificates/mozilla/DST_Root_CA_X3.crt
update-ca-certificates

```

If the `curl` command works as expected, (404 on `https://api.forestadmin.com` ), then the issue might come from the code. You could try to monkey-patch directly on your end, just in case you are still impacted by the `HTTPClient` issue declared [here](https://github.com/nahi/httpclient/issues/445).

Let me know if that helps 🙏

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 12:40pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/5 "2021-10-05T12:40:34Z")

</div>

Hello @anon16419211 !

Thank you for quick response!

I tried curl and got this response:

 ![Screenshot 2021-10-05 at 19.35.06](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/b/bac12f127ff9c3b6ecc61d47ac6451b16bc9e41f.png)

- try to upgrade your docker base image to a newer one, or

> Docker image was updated already.

- try to manually invalidate and update the certificate causing the issue via

> Certificated also were updated. Right now our website works fine with https on production. Please let  
> me know if I understood you wrong.
> 
> ![Screenshot 2021-10-05 at 19.42.25](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/2/2ba67ea889c4c1d3e8976b54206a10a340433724.jpeg)

- monkey-patch directly on your end

> Monkey-patch is already in production, also did not help. The code is above in the original request. I added inititalizer http\_client.rb
> 
> ![Screenshot 2021-10-05 at 19.39.40](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/a/a2f1ba6f9a0d7e79e319938c4c146767d36d2ec6.png)

I attached the code above of all the changes I have done, but still cannot manage to solve the problem.

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 1:03pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/6 "2021-10-05T13:03:12Z")

</div>

@kittinson

Ok thanks for the update, can you share me the logs from your server side on the /authentication call that is returning a 500 status code error?

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 1:27pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/7 "2021-10-05T13:27:02Z")

</div>

Here it is @lclisson :

 ![Screenshot 2021-10-05 at 20.26.33](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/9/982cce23a8a229eae9fb57cf65f4028bf2efa37e.jpeg)

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 2:12pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/8 "2021-10-05T14:12:21Z")

</div>

Thanks, it seems similar to previous authentication issue we add so I’m pretty sure we will manage to get your setup working again.

Can you confirm that you previously run `curl https://api.forestadmin.com` inside your docker container if your using one and not only the OS that run docker?

Thanks,

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 2:22pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/9 "2021-10-05T14:22:04Z")

</div>

> [@anon16419211](#):
>
> curl [https://api.forestadmin.com](https://api.forestadmin.com)

yes, that’s right! I just checked again and got the same response:

```javascript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>

```

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 2:40pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/10 "2021-10-05T14:40:35Z")

</div>

Can you try to run and tell me what it the response of it? 🙂

`rails console`

```javascript
clt = HTTPClient.new
clt.get('https://api.forestadmin.com')

```

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 2:42pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/11 "2021-10-05T14:42:21Z")

</div>

> [@anon16419211](#):
>
> ```javascript
> clt = HTTPClient.new
> clt.get('https://api.forestadmin.com')
> 
> ```

 ![Screenshot 2021-10-05 at 21.41.35](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/cdc0880ca04abd5c1ce74ea46acbe5693fd18ffa.jpeg)

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 2:53pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/12 "2021-10-05T14:53:27Z")

</div>

Ok you are not using our monkey patch but yours and it seems that there is an override. From what I can see your monkey patch is named _ **http\_client** _ and our is _ **httpClient** _. Can you try to rollback to version 7.2.1 and keep your monkey patch?

Let me know if it helps 🙂

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 3:09pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/14 "2021-10-05T15:09:20Z")

</div>

oh do you mean I gave a wrong name to file?

I simply create file in initializers folder http\_client.rb , should it be named httpClient.rb ?

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 3:13pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/15 "2021-10-05T15:13:49Z")

</div>

I deleted the patch and it worked!!! My production env in forest is back! Thank you @anon16419211 for your help ! Really appreciate it!

---

<div class="post-metadata">

**Author:** ![kittinson](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/kittinson/32/3271_2.png) [@kittinson](https://community.forestadmin.com/u/kittinson)\
**Post date:** [October 5, 2021, 3:16pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/16 "2021-10-05T15:16:45Z")

</div>

As a result, I deleted monkey patch and it worked. So all the rest I did was right!

- restarted server
- updated to forest\_liana 7.2.2
- deployed app again
- cleared cache
- update CORS configs
- added Forest\_url
- added client \_id

---

<div class="post-metadata">

**Author:** ![anon16419211](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@anon16419211](https://community.forestadmin.com/u/anon16419211)\
**Post date:** [October 5, 2021, 3:26pm UTC](https://community.forestadmin.com/t/unable-to-authenticate-you-500-or-400-error/3455/17 "2021-10-05T15:26:25Z")

</div>

Perfect, so glad to hear that your environment is back and work again !! Thanks for the help provided and your patience !
