forest_liana 7.6.14 → 7.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c0be19be3d243bda2e6ed0a9b926c6e1f1b24b7ab44187698d7fa08bdd8cfbb
4
- data.tar.gz: cd4076fa6837e825d545ccc0995dfef7a2326c652ab659ff615f582069b59c12
3
+ metadata.gz: 4f2e246fbfde70dc193c1ff1f71b97d5bb02c5c9ecee0a52073c5909b792e7b6
4
+ data.tar.gz: f267f5d490e264b288a0d0136c34f2e15d185760a2c4849bb7359a457ffb5ce2
5
5
  SHA512:
6
- metadata.gz: 0c34125014fb5025c6d9bfbe4c1fc4076d876ca2a436671743c5c529ac8b8c9cbb9add104ad03f01142a31ae17c0a04f3c9e76b73b1eb4785dfe01d4cbb1d3c2
7
- data.tar.gz: d189bf3ccd299236868d97c8fc32464c9c22f095c1c0a1c5f28c990b2690f63fe6f9c25f45c374b510849f3246dcd4e572b110194e0ca2ce0cc60e209d511133
6
+ metadata.gz: 449ecf89de01cfb538b57ac9768989d753e911f2ba67995290307d770a5bca72605e5766f83962d45e12d7052d7878b15a14402c0256687203d0107dc0b17669
7
+ data.tar.gz: eddb63f55196bbbea363d280a2610a0d42150ca554e55b6fcfaf998575041143346e7693bef6442dbd895d24981a185c35d4950f1950fa53cbd35d69aefebe13
@@ -6,21 +6,11 @@ module ForestLiana
6
6
  START_AUTHENTICATION_ROUTE = 'authentication'
7
7
  CALLBACK_AUTHENTICATION_ROUTE = 'authentication/callback'
8
8
  LOGOUT_ROUTE = 'authentication/logout'
9
- PUBLIC_ROUTES = [
10
- "/#{START_AUTHENTICATION_ROUTE}",
11
- "/#{CALLBACK_AUTHENTICATION_ROUTE}",
12
- "/#{LOGOUT_ROUTE}",
13
- ]
9
+ PUBLIC_ROUTES = %W[/#{START_AUTHENTICATION_ROUTE} /#{CALLBACK_AUTHENTICATION_ROUTE} /#{LOGOUT_ROUTE}]
14
10
 
15
11
  def initialize
16
12
  @authentication_service = ForestLiana::Authentication.new()
17
13
  end
18
-
19
- def get_callback_url
20
- File.join(ForestLiana.application_url, "/forest/#{CALLBACK_AUTHENTICATION_ROUTE}").to_s
21
- rescue => error
22
- raise "application_url is not valid or not defined" if error.is_a?(ArgumentError)
23
- end
24
14
 
25
15
  def get_and_check_rendering_id
26
16
  if !params.has_key?('renderingId')
@@ -28,7 +18,7 @@ module ForestLiana
28
18
  end
29
19
 
30
20
  rendering_id = params[:renderingId]
31
-
21
+
32
22
  if !(rendering_id.instance_of?(String) || rendering_id.instance_of?(Numeric)) || (rendering_id.instance_of?(Numeric) && rendering_id.nan?)
33
23
  raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_RENDERING_ID]
34
24
  end
@@ -36,15 +26,10 @@ module ForestLiana
36
26
  return rendering_id.to_i
37
27
  end
38
28
 
39
- def start_authentication
29
+ def start_authentication
40
30
  begin
41
31
  rendering_id = get_and_check_rendering_id()
42
- callback_url = get_callback_url()
43
-
44
- result = @authentication_service.start_authentication(
45
- callback_url,
46
- { 'renderingId' => rendering_id },
47
- )
32
+ result = @authentication_service.start_authentication({ 'renderingId' => rendering_id })
48
33
 
49
34
  render json: { authorizationUrl: result['authorization_url']}, status: 200
50
35
  rescue => error
@@ -55,12 +40,7 @@ module ForestLiana
55
40
 
56
41
  def authentication_callback
57
42
  begin
58
- callback_url = get_callback_url()
59
-
60
- token = @authentication_service.verify_code_and_generate_token(
61
- callback_url,
62
- params,
63
- )
43
+ token = @authentication_service.verify_code_and_generate_token(params)
64
44
 
65
45
  response_body = {
66
46
  token: token,
@@ -79,7 +59,7 @@ module ForestLiana
79
59
  begin
80
60
  if cookies.has_key?(:forest_session_token)
81
61
  forest_session_token = cookies[:forest_session_token]
82
-
62
+
83
63
  if forest_session_token
84
64
  response.set_cookie(
85
65
  'forest_session_token',
@@ -1,18 +1,18 @@
1
1
  module ForestLiana
2
2
  class Authentication
3
- def start_authentication(redirect_url, state)
4
- client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)
3
+ def start_authentication(state)
4
+ client = ForestLiana::OidcClientManager.get_client()
5
5
 
6
6
  authorization_url = client.authorization_uri({
7
7
  scope: 'openid email profile',
8
8
  state: state.to_s,
9
9
  })
10
-
10
+
11
11
  { 'authorization_url' => authorization_url }
12
12
  end
13
13
 
14
- def verify_code_and_generate_token(redirect_url, params)
15
- client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)
14
+ def verify_code_and_generate_token(params)
15
+ client = ForestLiana::OidcClientManager.get_client()
16
16
 
17
17
  rendering_id = parse_state(params['state'])
18
18
  client.authorization_code = params['code']
@@ -2,33 +2,32 @@ require 'openid_connect'
2
2
 
3
3
  module ForestLiana
4
4
  class OidcClientManager
5
- def self.get_client_for_callback_url(callback_url)
5
+ def self.get_client
6
6
  begin
7
7
  configuration = ForestLiana::OidcConfigurationRetriever.retrieve()
8
8
  if ForestLiana.forest_client_id.nil?
9
- client_data = Rails.cache.read("#{callback_url}-#{ForestLiana.env_secret}-client-data") || nil
9
+ client_data = Rails.cache.read("#{ForestLiana.env_secret}-client-data") || nil
10
10
  if client_data.nil?
11
11
  client_credentials = ForestLiana::OidcDynamicClientRegistrator.register({
12
12
  token_endpoint_auth_method: 'none',
13
- redirect_uris: [callback_url],
14
13
  registration_endpoint: configuration['registration_endpoint']
15
14
  })
16
- client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'] }
17
- Rails.cache.write("#{callback_url}-#{ForestLiana.env_secret}-client-data", client_data)
15
+ client_data = { :client_id => client_credentials['client_id'], :issuer => configuration['issuer'], :redirect_uri => client_credentials['redirect_uris'][0] }
16
+ Rails.cache.write("#{ForestLiana.env_secret}-client-data", client_data)
18
17
  end
19
18
  else
20
- client_data = { :client_id => ForestLiana.forest_client_id, :issuer => configuration['issuer'] }
19
+ client_data = { :client_id => ForestLiana.forest_client_id, :issuer => configuration['issuer'], :redirect_uri => File.join(ForestLiana.application_url, "/forest/authentication/callback").to_s }
21
20
  end
22
21
 
23
22
  OpenIDConnect::Client.new(
24
23
  identifier: client_data[:client_id],
25
- redirect_uri: callback_url,
24
+ redirect_uri: client_data[:redirect_uri],
26
25
  host: "#{client_data[:issuer].sub(/^https?\:\/\/(www.)?/,'')}",
27
26
  authorization_endpoint: '/oidc/auth',
28
27
  token_endpoint: '/oidc/token',
29
28
  )
30
29
  rescue => error
31
- Rails.cache.delete("#{callback_url}-#{ForestLiana.env_secret}-client-data")
30
+ Rails.cache.delete("#{ForestLiana.env_secret}-client-data")
32
31
  raise error
33
32
  end
34
33
  end
@@ -18,11 +18,19 @@ module ForestLiana
18
18
  ForestLiana.auth_secret = ForestLiana.auth_key
19
19
  end
20
20
 
21
- unless Rails.application.config.action_controller.perform_caching || Rails.env.test? || ForestLiana.forest_client_id
21
+ if ForestLiana.forest_client_id
22
+ FOREST_LOGGER.warn "DEPRECATION WARNING: The use of " \
23
+ "ForestLiana.forest_client_id is deprecated. It's not needed anymore."
24
+ end
25
+
26
+ if Rails.application.secrets.forest_application_url
27
+ FOREST_LOGGER.warn "DEPRECATION WARNING: The use of " \
28
+ "The secret forest_application_url is deprecated. It's not needed anymore."
29
+ end
30
+
31
+ unless Rails.application.config.action_controller.perform_caching || Rails.env.test?
22
32
  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"
33
+ "For a development environment, run: `rails dev:cache`"
26
34
  end
27
35
 
28
36
  fetch_models
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "7.6.14"
2
+ VERSION = "7.7.0"
3
3
  end
@@ -5,7 +5,6 @@ module ForestLiana
5
5
  desc 'Forest Rails Liana installation generator'
6
6
 
7
7
  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'
9
8
 
10
9
  def install
11
10
  if ForestLiana.env_secret.present?
@@ -28,42 +27,35 @@ module ForestLiana
28
27
  if File.exist? 'config/secrets.yml'
29
28
  inject_into_file 'config/secrets.yml', after: "development:\n" do
30
29
  " forest_env_secret: #{env_secret}\n" +
31
- " forest_auth_secret: #{auth_secret}\n" +
32
- " forest_application_url: #{application_url}\n"
30
+ " forest_auth_secret: #{auth_secret}\n"
33
31
  end
34
32
 
35
33
  inject_into_file 'config/secrets.yml', after: "staging:\n", force: true do
36
34
  " forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
37
- " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
38
- " forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
35
+ " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
39
36
  end
40
37
 
41
38
  inject_into_file 'config/secrets.yml', after: "production:\n", force: true do
42
39
  " forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
43
- " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
44
- " forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
40
+ " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
45
41
  end
46
42
  else
47
43
  create_file 'config/secrets.yml' do
48
44
  "development:\n" +
49
45
  " forest_env_secret: #{env_secret}\n" +
50
46
  " forest_auth_secret: #{auth_secret}\n" +
51
- " forest_application_url: #{application_url}\n" +
52
47
  "staging:\n" +
53
48
  " forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
54
49
  " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
55
- " forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n" +
56
50
  "production:\n" +
57
51
  " forest_env_secret: <%= ENV[\"FOREST_ENV_SECRET\"] %>\n" +
58
- " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n" +
59
- " forest_application_url: <%= ENV[\"FOREST_APPLICATION_URL\"] %>\n"
52
+ " forest_auth_secret: <%= ENV[\"FOREST_AUTH_SECRET\"] %>\n"
60
53
  end
61
54
  end
62
55
 
63
56
  initializer 'forest_liana.rb' do
64
57
  "ForestLiana.env_secret = Rails.application.secrets.forest_env_secret" +
65
- "\nForestLiana.auth_secret = Rails.application.secrets.forest_auth_secret" +
66
- "\nForestLiana.application_url = Rails.application.secrets.forest_application_url"
58
+ "\nForestLiana.auth_secret = Rails.application.secrets.forest_auth_secret"
67
59
  end
68
60
  end
69
61
  end
@@ -0,0 +1,6 @@
1
+ namespace :forest do
2
+ desc "Clear the OIDC data cache key"
3
+ task clear: :environment do
4
+ Rails.cache.delete("#{ForestLiana.env_secret}-client-data")
5
+ end
6
+ end
@@ -14,7 +14,7 @@ describe "Authentications", type: :request do
14
14
  }', :symbolize_names => false)
15
15
  }
16
16
  allow(ForestLiana::ForestApiRequester).to receive(:post) {
17
- instance_double(HTTParty::Response, body: '{ "client_id": "random_id" }', code: 201)
17
+ instance_double(HTTParty::Response, body: '{ "client_id": "random_id", "redirect_uris": ["http://localhost:3000/forest/authentication/callback"] }', code: 201)
18
18
  }
19
19
  allow_any_instance_of(OpenIDConnect::Client).to receive(:access_token!) {
20
20
  OpenIDConnect::AccessToken.new(access_token: 'THE-ACCESS-TOKEN', client: instance_double(OpenIDConnect::Client))
@@ -22,11 +22,11 @@ describe "Authentications", type: :request do
22
22
  end
23
23
 
24
24
  after do
25
- Rails.cache.delete(URI.join(ForestLiana.application_url, ForestLiana::Engine.routes.url_helpers.authentication_callback_path).to_s)
25
+ Rails.cache.delete("#{ForestLiana.env_secret}-client-data")
26
26
  end
27
27
 
28
28
  describe "POST /authentication" do
29
- before() do
29
+ before() do
30
30
  post ForestLiana::Engine.routes.url_helpers.authentication_path, params: '{"renderingId":"42"}', headers: {
31
31
  'Accept' => 'application/json',
32
32
  'Content-Type' => 'application/json',
@@ -44,10 +44,10 @@ describe "Authentications", type: :request do
44
44
  end
45
45
 
46
46
  describe "GET /authentication/callback" do
47
- before() do
47
+ before() do
48
48
  response = '{"data":{"id":666,"attributes":{"first_name":"Alice","last_name":"Doe","email":"alice@forestadmin.com","teams":[1,2,3],"role":"Test","tags":[{"key":"city","value":"Paris"}]}}}'
49
49
  allow(ForestLiana::ForestApiRequester).to receive(:get).with(
50
- "/liana/v2/renderings/42/authorization", { :headers => { "forest-token" => "THE-ACCESS-TOKEN" }, :query=> {} }
50
+ "/liana/v2/renderings/42/authorization", { :headers => { "forest-token" => "THE-ACCESS-TOKEN" }, :query => {} }
51
51
  ).and_return(
52
52
  instance_double(HTTParty::Response, :body => response, :code => 200)
53
53
  )
@@ -86,7 +86,7 @@ describe "Authentications", type: :request do
86
86
  end
87
87
 
88
88
  describe "POST /authentication/logout" do
89
- before() do
89
+ before() do
90
90
  post ForestLiana::Engine.routes.url_helpers.authentication_logout_path, params: { :renderingId => 42 }, :headers => headers
91
91
  end
92
92
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.6.14
4
+ version: 7.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -316,6 +316,7 @@ files:
316
316
  - lib/forest_liana/schema_file_updater.rb
317
317
  - lib/forest_liana/version.rb
318
318
  - lib/generators/forest_liana/install_generator.rb
319
+ - lib/tasks/clear_oidc_data.rake
319
320
  - lib/tasks/display_apimap.rake
320
321
  - lib/tasks/send_apimap.rake
321
322
  - spec/config/initializers/logger_spec.rb