Skip to content

Commit 3fb83d1

Browse files
fix(authentication): add missing environment variable generation and check if caching is enabled (#epz6k0) (#431)
Co-authored-by: Arnaud Besnier <[email protected]>
1 parent 29e471c commit 3fb83d1

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

app/controllers/forest_liana/authentication_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def authentication_callback
8686
render json: response_body, status: 200
8787

8888
rescue => error
89-
render json: { errors: [{ status: error.error_code || 500, detail: error.message }] },
89+
render json: { errors: [{ status: error.try(:error_code) || 500, detail: error.message }] },
9090
status: error.status || :internal_server_error, serializer: nil
9191
end
9292
end

app/services/forest_liana/oidc_client_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def self.get_client_for_callback_url(callback_url)
1515
registration_endpoint: configuration['registration_endpoint']
1616
})
1717
else
18-
client_credentials['client_id'] = ForestLiana.forest_client_id
18+
client_credentials = { 'client_id' => ForestLiana.forest_client_id }
1919
end
2020

2121
client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'] }

lib/forest_liana/bootstrapper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ def initialize
1818
ForestLiana.auth_secret = ForestLiana.auth_key
1919
end
2020

21+
unless Rails.application.config.action_controller.perform_caching || Rails.env.test? || ForestLiana.forest_client_id
22+
FOREST_LOGGER.error "You need to enable caching on your environment to use Forest Admin.\n" \
23+
"For a development environment, run: `rails dev:cache`\n" \
24+
"Or setup a static forest_client_id by following this part of the documentation:\n" \
25+
"https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-rails/upgrade-to-v6#setup-a-static-clientid"
26+
end
27+
2128
fetch_models
2229
check_integrations_setup
2330
namespace_duplicated_models

lib/generators/forest_liana/install_generator.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class InstallGenerator < Rails::Generators::Base
55
desc 'Forest Rails Liana installation generator'
66

77
argument :env_secret, type: :string, required: true, desc: 'required', banner: 'env_secret'
8+
argument :application_url, type: :string, required: false, desc: 'optional', banner: 'application_url', default: 'http://localhost:3000'
89

910
def install
1011
if ForestLiana.env_secret.present?
@@ -27,35 +28,42 @@ def install
2728
if File.exist? 'config/secrets.yml'
2829
inject_into_file 'config/secrets.yml', after: "development:\n" do
2930
" forest_env_secret: #{env_secret}\n" +
30-
" forest_auth_secret: #{auth_secret}\n"
31+
" forest_auth_secret: #{auth_secret}\n" +
32+
" forest_application_url: #{application_url}\n"
3133
end
3234

3335
inject_into_file 'config/secrets.yml', after: "staging:\n", force: true do
3436
" forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
35-
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
37+
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
38+
" forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
3639
end
3740

3841
inject_into_file 'config/secrets.yml', after: "production:\n", force: true do
3942
" forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
40-
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
43+
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
44+
" forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
4145
end
4246
else
4347
create_file 'config/secrets.yml' do
4448
"development:\n" +
4549
" forest_env_secret: #{env_secret}\n" +
4650
" forest_auth_secret: #{auth_secret}\n" +
51+
" forest_application_url: #{application_url}\n" +
4752
"staging:\n" +
4853
" forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
4954
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
55+
" forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n" +
5056
"production:\n" +
5157
" forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
52-
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
58+
" forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
59+
" forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
5360
end
5461
end
5562

5663
initializer 'forest_liana.rb' do
5764
"ForestLiana.env_secret = Rails.application.secrets.forest_env_secret" +
58-
"\nForestLiana.auth_secret = Rails.application.secrets.forest_auth_secret"
65+
"\nForestLiana.auth_secret = Rails.application.secrets.forest_auth_secret" +
66+
"\nForestLiana.application_url = Rails.application.secrets.forest_application_url"
5967
end
6068
end
6169
end

0 commit comments

Comments
 (0)