500 when connecting to staging environment

Expected behavior

I’m connected on the “Production Environnement”. When I click on the environment list on the top left, and select “STAGING”, I’d like to go the staging environment of forest admin.

Actual behavior

I get an error :
image

Failure Logs

In the Console, I can see that the auth url “/forest/authentication” is replying a 500 :
{"errors":[{"status":500,"detail":"The registration to the authentication API failed, response: {\"error\":\"invalid_redirect_uri\",\"error_description\":\"Redirect uris must be an array of valid urls\"}"}]}

Here is what I see on the app log :

2021-04-06T21:12:35.228165+00:00 app[web.1]: I, [2021-04-06T21:12:35.228057 #4]  INFO -- : [1b78c769-578a-4aee-a3b8-f06ea91173a6] Started POST "/forest/authentication" for 91.168.129.244 at 2021-04-06 21:12:35 +0000
2021-04-06T21:12:35.229967+00:00 app[web.1]: I, [2021-04-06T21:12:35.229833 #4]  INFO -- : [1b78c769-578a-4aee-a3b8-f06ea91173a6] Processing by ForestLiana::AuthenticationController#start_authentication as */*
2021-04-06T21:12:35.230067+00:00 app[web.1]: I, [2021-04-06T21:12:35.229983 #4]  INFO -- : [1b78c769-578a-4aee-a3b8-f06ea91173a6]   Parameters: {"renderingId"=>"26856"}
2021-04-06T21:12:35.314968+00:00 app[web.1]: I, [2021-04-06T21:12:35.314834 #4]  INFO -- : [1b78c769-578a-4aee-a3b8-f06ea91173a6] Completed 500 Internal Server Error in 85ms (Views: 0.4ms | ActiveRecord: 0.0ms)

Context

I just updated the app from ruby 2.6.3 to ruby 2.6.6.
the bundle install command updated forest-liana :
forest_liana (3.3.0) → forest_liana (6.2.3)

Database didn’t change, it is still postgresql 9.6

For now, I just pushed those change to staging and not on production yet.
All tests passed on staging, and the api is working well for a normal usage.
The only thing that fails is forest admin authentification on the staging environment.
forest admin on production works well.

Project name : Resteo

thanks for your help !
Greg

Hi @Gregory_Derderian :wave: welcome to our community !

Thank you for your detailed report.

I see that you bump from forest_liana (3.3.0) to forest_liana (6.2.3). There is many breaking changes for those major updates. Have you follow the upgrade notes ?

In your case, I think you forgot to add the forest_application_url environment variable (Note Rails v5 to v6).

Let me know if it helps.
Have a nice day.

Morgan

Hi @morganperre and thanks for your reply !

You’re right, I didn’t realize the breaking changes.

I applied now all of them, 3 to 4, 4 to 5 and 5 to 6.

On the dev environment, it works perfectly well.

On staging, the authentification is now working:
image

But now I have an error with the callback endpoint that seems to be related with the CORS policy:

Access to fetch at 'https://sresteo.herokuapp.com/forest/authentication/callback?code=(...)' from origin 'https://app.forestadmin.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

But I did update the cors on the app … :
image

Do you have an idea of what I missed ?
thanks a lot
Greg

Hello @Gregory_Derderian,

Can you share with us the result of the OPTIONS request made by the browser before sending the POST that fails due to cors?

We will need the entire response, with response headers of this request. You’ll find it in the network tab of the developer tools of your browser.

Hello @GuillaumeGautreau

Here is the OPTIONS request :
image

Thanks !
Greg

Ok, thanks.

Then the problem comes from this request that gets a 405 from your backend. Do you have any clue about the reason why this request gets rejected?

I’m not aware of any piece of code in forest-rails that returns a 405.

I think I understand why.

Our API is on Rails.
Our UI is on Reacts.

The url I gave is the App URL, not the API URL…

I update the secrets and will tell you.

1 Like

All good now ! thanks @GuillaumeGautreau & @morganperre

1 Like