forest_liana 5.3.2 → 6.0.0.pre.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/forest_liana/actions_controller.rb +8 -1
- data/app/controllers/forest_liana/application_controller.rb +1 -7
- data/app/controllers/forest_liana/authentication_controller.rb +122 -0
- data/app/controllers/forest_liana/base_controller.rb +4 -0
- data/app/controllers/forest_liana/resources_controller.rb +14 -17
- data/app/controllers/forest_liana/router.rb +2 -2
- data/app/controllers/forest_liana/sessions_controller.rb +1 -1
- data/app/controllers/forest_liana/smart_actions_controller.rb +10 -5
- data/app/controllers/forest_liana/stats_controller.rb +5 -5
- data/app/helpers/forest_liana/adapter_helper.rb +1 -1
- data/app/serializers/forest_liana/schema_serializer.rb +2 -2
- data/app/services/forest_liana/apimap_sorter.rb +1 -1
- data/app/services/forest_liana/authentication.rb +59 -0
- data/app/services/forest_liana/authorization_getter.rb +12 -20
- data/app/services/forest_liana/forest_api_requester.rb +14 -5
- data/app/services/forest_liana/ip_whitelist_checker.rb +1 -1
- data/app/services/forest_liana/login_handler.rb +3 -11
- data/app/services/forest_liana/oidc_client_manager.rb +34 -0
- data/app/services/forest_liana/oidc_configuration_retriever.rb +12 -0
- data/app/services/forest_liana/oidc_dynamic_client_registrator.rb +67 -0
- data/app/services/forest_liana/permissions_checker.rb +117 -56
- data/app/services/forest_liana/permissions_formatter.rb +52 -0
- data/app/services/forest_liana/permissions_getter.rb +52 -17
- data/app/services/forest_liana/query_stat_getter.rb +5 -5
- data/app/services/forest_liana/scope_validator.rb +8 -7
- data/app/services/forest_liana/token.rb +27 -0
- data/app/services/forest_liana/utils/beta_schema_utils.rb +13 -0
- data/config/initializers/error-messages.rb +20 -0
- data/config/routes.rb +5 -0
- data/lib/forest_liana.rb +1 -0
- data/lib/forest_liana/bootstrapper.rb +1 -1
- data/lib/forest_liana/collection.rb +2 -2
- data/lib/forest_liana/engine.rb +9 -0
- data/lib/forest_liana/json_printer.rb +1 -1
- data/lib/forest_liana/version.rb +1 -1
- data/spec/dummy/app/assets/config/manifest.js +1 -0
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/initializers/forest_liana.rb +1 -0
- data/spec/dummy/db/migrate/20190226172951_create_user.rb +1 -1
- data/spec/dummy/db/migrate/20190226173051_create_isle.rb +1 -1
- data/spec/dummy/db/migrate/20190226174951_create_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716130830_add_age_to_tree.rb +1 -1
- data/spec/dummy/db/migrate/20190716135241_add_type_to_user.rb +1 -1
- data/spec/dummy/db/schema.rb +18 -20
- data/spec/requests/actions_controller_spec.rb +46 -11
- data/spec/requests/authentications_spec.rb +105 -0
- data/spec/requests/resources_spec.rb +4 -4
- data/spec/requests/sessions_spec.rb +53 -0
- data/spec/services/forest_liana/permissions_checker_acl_disabled_spec.rb +711 -0
- data/spec/services/forest_liana/permissions_checker_acl_enabled_spec.rb +831 -0
- data/spec/services/forest_liana/permissions_formatter_spec.rb +222 -0
- data/spec/services/forest_liana/permissions_getter_spec.rb +83 -0
- data/spec/spec_helper.rb +3 -0
- data/test/dummy/app/assets/config/manifest.js +1 -0
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/migrate/20150608130516_create_date_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131430_create_integer_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131603_create_decimal_field.rb +1 -1
- data/test/dummy/db/migrate/20150608131610_create_float_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132159_create_boolean_field.rb +1 -1
- data/test/dummy/db/migrate/20150608132621_create_string_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133038_create_belongs_to_field.rb +1 -1
- data/test/dummy/db/migrate/20150608133044_create_has_one_field.rb +1 -1
- data/test/dummy/db/migrate/20150608150016_create_has_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150609114636_create_belongs_to_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150612112520_create_has_and_belongs_to_many_field.rb +1 -1
- data/test/dummy/db/migrate/20150616150629_create_polymorphic_field.rb +1 -1
- data/test/dummy/db/migrate/20150623115554_create_has_many_class_name_field.rb +1 -1
- data/test/dummy/db/migrate/20150814081918_create_has_many_through_field.rb +1 -1
- data/test/dummy/db/migrate/20160627172810_create_owner.rb +1 -1
- data/test/dummy/db/migrate/20160627172951_create_tree.rb +1 -1
- data/test/dummy/db/migrate/20160628173505_add_timestamps.rb +1 -1
- data/test/dummy/db/migrate/20170614141921_create_serialize_field.rb +1 -1
- data/test/dummy/db/migrate/20181111162121_create_references_table.rb +1 -1
- metadata +71 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea2912357a0fabb3b4c6527d848f9b728d2394c83155cd77314e54f66c1d8e2
|
4
|
+
data.tar.gz: 69863c89f2668cb142f54ddc5a9fcc1c473417cef56fc307765e53a686572bd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e36ad5a50676182d85029fe634e2874328c537bff2679e5a99661393e5d23c84fa3e30c165c376c06c0e8bc013beffc8d0b2497408276322a0811de8fbf222
|
7
|
+
data.tar.gz: 3bb4aec7204cced667652ac92f1aef9e4897d282a578408603c2fd98b7b37079565ea39d58ef1d26ee4f62af545c41bd2e56666df4d0335f7b53a455c705f17a
|
@@ -53,7 +53,14 @@ module ForestLiana
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# Apply result on fields (transform the object back to an array), preserve order.
|
56
|
-
fields = action.fields.map
|
56
|
+
fields = action.fields.map do |field|
|
57
|
+
updated_field = result[field[:field]]
|
58
|
+
# Reset `value` when not present in `enums` (which means `enums` has changed).
|
59
|
+
if updated_field[:enums].is_a?(Array) && !updated_field[:enums].include?(updated_field[:value])
|
60
|
+
updated_field[:value] = nil
|
61
|
+
end
|
62
|
+
updated_field
|
63
|
+
end
|
57
64
|
|
58
65
|
render serializer: nil, json: { fields: fields}, status: :ok
|
59
66
|
end
|
@@ -3,8 +3,6 @@ require 'csv'
|
|
3
3
|
|
4
4
|
module ForestLiana
|
5
5
|
class ApplicationController < ForestLiana::BaseController
|
6
|
-
REGEX_COOKIE_SESSION_TOKEN = /forest_session_token=([^;]*)/;
|
7
|
-
|
8
6
|
def self.papertrail?
|
9
7
|
Object.const_get('PaperTrail::Version').is_a?(Class) rescue false
|
10
8
|
end
|
@@ -64,7 +62,7 @@ module ForestLiana
|
|
64
62
|
token = request.headers['Authorization'].split.second
|
65
63
|
# NOTICE: Necessary for downloads authentication.
|
66
64
|
elsif request.headers['cookie']
|
67
|
-
match = REGEX_COOKIE_SESSION_TOKEN.match(request.headers['cookie'])
|
65
|
+
match = ForestLiana::Token::REGEX_COOKIE_SESSION_TOKEN.match(request.headers['cookie'])
|
68
66
|
token = match[1] if match && match[1]
|
69
67
|
end
|
70
68
|
|
@@ -97,10 +95,6 @@ module ForestLiana
|
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
100
|
-
def route_not_found
|
101
|
-
head :not_found
|
102
|
-
end
|
103
|
-
|
104
98
|
def internal_server_error
|
105
99
|
head :internal_server_error
|
106
100
|
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module ForestLiana
|
5
|
+
class AuthenticationController < ForestLiana::BaseController
|
6
|
+
START_AUTHENTICATION_ROUTE = 'authentication'
|
7
|
+
CALLBACK_AUTHENTICATION_ROUTE = 'authentication/callback'
|
8
|
+
LOGOUT_ROUTE = 'authentication/logout';
|
9
|
+
PUBLIC_ROUTES = [
|
10
|
+
"/#{START_AUTHENTICATION_ROUTE}",
|
11
|
+
"/#{CALLBACK_AUTHENTICATION_ROUTE}",
|
12
|
+
"/#{LOGOUT_ROUTE}",
|
13
|
+
]
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@authentication_service = ForestLiana::Authentication.new()
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_callback_url
|
20
|
+
URI.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
|
+
|
25
|
+
def get_and_check_rendering_id
|
26
|
+
if !params.has_key?('renderingId')
|
27
|
+
raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:MISSING_RENDERING_ID]
|
28
|
+
end
|
29
|
+
|
30
|
+
rendering_id = params[:renderingId]
|
31
|
+
|
32
|
+
if !(rendering_id.instance_of?(String) || rendering_id.instance_of?(Numeric)) || (rendering_id.instance_of?(Numeric) && rendering_id.nan?)
|
33
|
+
raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_RENDERING_ID]
|
34
|
+
end
|
35
|
+
|
36
|
+
return rendering_id.to_i
|
37
|
+
end
|
38
|
+
|
39
|
+
def start_authentication
|
40
|
+
begin
|
41
|
+
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
|
+
)
|
48
|
+
|
49
|
+
redirect_to(result['authorization_url'])
|
50
|
+
rescue => error
|
51
|
+
render json: { errors: [{ status: 500, detail: error.message }] },
|
52
|
+
status: :internal_server_error, serializer: nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def authentication_callback
|
57
|
+
begin
|
58
|
+
callback_url = get_callback_url()
|
59
|
+
|
60
|
+
token = @authentication_service.verify_code_and_generate_token(
|
61
|
+
callback_url,
|
62
|
+
params,
|
63
|
+
)
|
64
|
+
|
65
|
+
response.set_cookie(
|
66
|
+
'forest_session_token',
|
67
|
+
{
|
68
|
+
value: token,
|
69
|
+
httponly: true,
|
70
|
+
secure: true,
|
71
|
+
expires: ForestLiana::Token.expiration_in_days,
|
72
|
+
samesite: 'none',
|
73
|
+
path: '/'
|
74
|
+
},
|
75
|
+
)
|
76
|
+
|
77
|
+
response_body = {
|
78
|
+
tokenData: JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0]
|
79
|
+
}
|
80
|
+
|
81
|
+
# The token is sent decoded, because we don't want to share the whole, signed token
|
82
|
+
# that is used to authenticate people
|
83
|
+
# but the token itself contains interesting values, such as its expiration date
|
84
|
+
response_body[:token] = token if !ForestLiana.application_url.start_with?('https://')
|
85
|
+
|
86
|
+
render json: response_body, status: 200
|
87
|
+
|
88
|
+
rescue => error
|
89
|
+
render json: { errors: [{ status: 500, detail: error.message }] },
|
90
|
+
status: :internal_server_error, serializer: nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def logout
|
95
|
+
begin
|
96
|
+
if cookies.has_key?(:forest_session_token)
|
97
|
+
forest_session_token = cookies[:forest_session_token]
|
98
|
+
|
99
|
+
if forest_session_token
|
100
|
+
response.set_cookie(
|
101
|
+
'forest_session_token',
|
102
|
+
{
|
103
|
+
value: forest_session_token,
|
104
|
+
httponly: true,
|
105
|
+
secure: true,
|
106
|
+
expires: Time.at(0),
|
107
|
+
samesite: 'none',
|
108
|
+
path: '/'
|
109
|
+
},
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
render json: {}, status: 204
|
115
|
+
rescue => error
|
116
|
+
render json: { errors: [{ status: 500, detail: error.message }] },
|
117
|
+
status: :internal_server_error, serializer: nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
@@ -16,18 +16,15 @@ module ForestLiana
|
|
16
16
|
def index
|
17
17
|
begin
|
18
18
|
if request.format == 'csv'
|
19
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
20
|
-
return head :forbidden unless checker.is_authorized?
|
21
|
-
elsif params.has_key?(:searchToEdit)
|
22
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, 'searchToEdit', @rendering_id)
|
19
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'exportEnabled', @rendering_id, user_id: forest_user['id'])
|
23
20
|
return head :forbidden unless checker.is_authorized?
|
24
21
|
else
|
25
22
|
checker = ForestLiana::PermissionsChecker.new(
|
26
23
|
@resource,
|
27
|
-
'
|
24
|
+
'browseEnabled',
|
28
25
|
@rendering_id,
|
29
|
-
|
30
|
-
get_collection_list_permission_info(forest_user, request)
|
26
|
+
user_id: forest_user['id'],
|
27
|
+
collection_list_parameters: get_collection_list_permission_info(forest_user, request)
|
31
28
|
)
|
32
29
|
return head :forbidden unless checker.is_authorized?
|
33
30
|
end
|
@@ -59,10 +56,10 @@ module ForestLiana
|
|
59
56
|
begin
|
60
57
|
checker = ForestLiana::PermissionsChecker.new(
|
61
58
|
@resource,
|
62
|
-
'
|
59
|
+
'browseEnabled',
|
63
60
|
@rendering_id,
|
64
|
-
|
65
|
-
get_collection_list_permission_info(forest_user, request)
|
61
|
+
user_id: forest_user['id'],
|
62
|
+
collection_list_parameters: get_collection_list_permission_info(forest_user, request)
|
66
63
|
)
|
67
64
|
return head :forbidden unless checker.is_authorized?
|
68
65
|
|
@@ -89,7 +86,7 @@ module ForestLiana
|
|
89
86
|
|
90
87
|
def show
|
91
88
|
begin
|
92
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
89
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'readEnabled', @rendering_id, user_id: forest_user['id'])
|
93
90
|
return head :forbidden unless checker.is_authorized?
|
94
91
|
|
95
92
|
getter = ForestLiana::ResourceGetter.new(@resource, params)
|
@@ -104,7 +101,7 @@ module ForestLiana
|
|
104
101
|
|
105
102
|
def create
|
106
103
|
begin
|
107
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
104
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'addEnabled', @rendering_id, user_id: forest_user['id'])
|
108
105
|
return head :forbidden unless checker.is_authorized?
|
109
106
|
|
110
107
|
creator = ForestLiana::ResourceCreator.new(@resource, params)
|
@@ -127,7 +124,7 @@ module ForestLiana
|
|
127
124
|
|
128
125
|
def update
|
129
126
|
begin
|
130
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
127
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'editEnabled', @rendering_id, user_id: forest_user['id'])
|
131
128
|
return head :forbidden unless checker.is_authorized?
|
132
129
|
|
133
130
|
updater = ForestLiana::ResourceUpdater.new(@resource, params)
|
@@ -149,7 +146,7 @@ module ForestLiana
|
|
149
146
|
end
|
150
147
|
|
151
148
|
def destroy
|
152
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
149
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'deleteEnabled', @rendering_id, user_id: forest_user['id'])
|
153
150
|
return head :forbidden unless checker.is_authorized?
|
154
151
|
|
155
152
|
@resource.destroy(params[:id]) if @resource.exists?(params[:id])
|
@@ -161,7 +158,7 @@ module ForestLiana
|
|
161
158
|
end
|
162
159
|
|
163
160
|
def destroy_bulk
|
164
|
-
checker = ForestLiana::PermissionsChecker.new(@resource, '
|
161
|
+
checker = ForestLiana::PermissionsChecker.new(@resource, 'deleteEnabled', @rendering_id, user_id: forest_user['id'])
|
165
162
|
return head :forbidden unless checker.is_authorized?
|
166
163
|
|
167
164
|
ids = ForestLiana::ResourcesGetter.get_ids_from_request(params)
|
@@ -245,8 +242,8 @@ module ForestLiana
|
|
245
242
|
@collection ||= ForestLiana.apimap.find { |collection| collection.name.to_s == collection_name }
|
246
243
|
end
|
247
244
|
|
248
|
-
# NOTICE: Return a formatted object containing the request condition filters and
|
249
|
-
# the user id used by the scope validator class to validate if scope is
|
245
|
+
# NOTICE: Return a formatted object containing the request condition filters and
|
246
|
+
# the user id used by the scope validator class to validate if scope is
|
250
247
|
# in request
|
251
248
|
def get_collection_list_permission_info(user, collection_list_request)
|
252
249
|
{
|
@@ -7,7 +7,7 @@ class ForestLiana::Router
|
|
7
7
|
if resource.nil?
|
8
8
|
FOREST_LOGGER.error "Routing error: Resource not found for collection #{collection_name}."
|
9
9
|
FOREST_LOGGER.error "If this is a Smart Collection, please ensure your Smart Collection routes are defined before the mounted ForestLiana::Engine?"
|
10
|
-
ForestLiana::
|
10
|
+
ForestLiana::BaseController.action(:route_not_found).call(env)
|
11
11
|
else
|
12
12
|
begin
|
13
13
|
component_prefix = ForestLiana.component_prefix(resource)
|
@@ -40,7 +40,7 @@ class ForestLiana::Router
|
|
40
40
|
controller.action(action.to_sym).call(env)
|
41
41
|
rescue NoMethodError => exception
|
42
42
|
FOREST_LOGGER.error "Routing error: #{exception}\n#{exception.backtrace.join("\n\t")}"
|
43
|
-
ForestLiana::
|
43
|
+
ForestLiana::BaseController.action(:route_not_found).call(env)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -85,7 +85,7 @@ module ForestLiana
|
|
85
85
|
# NOTICE: Set a cookie to ensure secure authentication using export feature.
|
86
86
|
# NOTICE: The token is empty at first authentication step if the 2FA option is active.
|
87
87
|
if reponse_data[:token]
|
88
|
-
response.set_cookie("forest_session_token", { value: reponse_data[:token], expires: (
|
88
|
+
response.set_cookie("forest_session_token", { value: reponse_data[:token], expires: (ForestLiana::Token.expiration_in_days) })
|
89
89
|
end
|
90
90
|
|
91
91
|
render(json: reponse_data, serializer: nil)
|
@@ -19,14 +19,15 @@ module ForestLiana
|
|
19
19
|
|
20
20
|
def check_permission_for_smart_route
|
21
21
|
begin
|
22
|
-
|
22
|
+
|
23
23
|
smart_action_request = get_smart_action_request
|
24
24
|
if !smart_action_request.nil? && smart_action_request.has_key?(:smart_action_id)
|
25
25
|
checker = ForestLiana::PermissionsChecker.new(
|
26
26
|
find_resource(smart_action_request[:collection_name]),
|
27
27
|
'actions',
|
28
28
|
@rendering_id,
|
29
|
-
|
29
|
+
user_id: forest_user['id'],
|
30
|
+
smart_action_request_info: get_smart_action_request_info
|
30
31
|
)
|
31
32
|
return head :forbidden unless checker.is_authorized?
|
32
33
|
else
|
@@ -54,10 +55,14 @@ module ForestLiana
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
+
# smart action permissions are retrieved from the action's endpoint and http_method
|
59
|
+
def get_smart_action_request_info
|
60
|
+
endpoint = request.fullpath
|
61
|
+
# Trim starting '/'
|
62
|
+
endpoint[0] = '' if endpoint[0] == '/'
|
58
63
|
{
|
59
|
-
|
60
|
-
|
64
|
+
endpoint: endpoint,
|
65
|
+
http_method: request.request_method
|
61
66
|
}
|
62
67
|
end
|
63
68
|
end
|
@@ -6,11 +6,11 @@ module ForestLiana
|
|
6
6
|
before_action :find_resource, except: [:get_with_live_query]
|
7
7
|
end
|
8
8
|
|
9
|
-
CHART_TYPE_VALUE = 'Value'
|
10
|
-
CHART_TYPE_PIE = 'Pie'
|
11
|
-
CHART_TYPE_LINE = 'Line'
|
12
|
-
CHART_TYPE_LEADERBOARD = 'Leaderboard'
|
13
|
-
CHART_TYPE_OBJECTIVE = 'Objective'
|
9
|
+
CHART_TYPE_VALUE = 'Value'
|
10
|
+
CHART_TYPE_PIE = 'Pie'
|
11
|
+
CHART_TYPE_LINE = 'Line'
|
12
|
+
CHART_TYPE_LEADERBOARD = 'Leaderboard'
|
13
|
+
CHART_TYPE_OBJECTIVE = 'Objective'
|
14
14
|
|
15
15
|
def get
|
16
16
|
case params[:type]
|
@@ -52,7 +52,7 @@ class ForestLiana::SchemaSerializer
|
|
52
52
|
@included << format_child_content('segments', segment_id, segment)
|
53
53
|
end
|
54
54
|
else
|
55
|
-
collection_serialized[:attributes][attribute.to_sym] = value
|
55
|
+
collection_serialized[:attributes][attribute.to_sym] = value
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -75,7 +75,7 @@ class ForestLiana::SchemaSerializer
|
|
75
75
|
}
|
76
76
|
|
77
77
|
object.each do |attribute, value|
|
78
|
-
child_serialized[:attributes][attribute.to_sym] = value
|
78
|
+
child_serialized[:attributes][attribute.to_sym] = value
|
79
79
|
end
|
80
80
|
|
81
81
|
child_serialized
|
@@ -61,7 +61,7 @@ module ForestLiana
|
|
61
61
|
def perform
|
62
62
|
begin
|
63
63
|
@apimap = reorder_keys_basic(@apimap)
|
64
|
-
sort_array_of_objects(@apimap['data'])
|
64
|
+
sort_array_of_objects(@apimap['data'])
|
65
65
|
@apimap['data'].map! do |collection|
|
66
66
|
collection = reorder_keys_child(collection)
|
67
67
|
collection['attributes'] = reorder_collection_attributes(collection['attributes'])
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ForestLiana
|
2
|
+
class Authentication
|
3
|
+
def start_authentication(redirect_url, state)
|
4
|
+
client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)
|
5
|
+
|
6
|
+
authorization_url = client.authorization_uri({
|
7
|
+
scope: 'openid email profile',
|
8
|
+
state: state.to_s,
|
9
|
+
})
|
10
|
+
|
11
|
+
{ 'authorization_url' => authorization_url }
|
12
|
+
end
|
13
|
+
|
14
|
+
def verify_code_and_generate_token(redirect_url, params)
|
15
|
+
client = ForestLiana::OidcClientManager.get_client_for_callback_url(redirect_url)
|
16
|
+
|
17
|
+
rendering_id = parse_state(params['state'])
|
18
|
+
client.authorization_code = params['code']
|
19
|
+
|
20
|
+
if Rails.env.development? || Rails.env.test?
|
21
|
+
OpenIDConnect.http_config do |config|
|
22
|
+
config.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
23
|
+
end
|
24
|
+
end
|
25
|
+
access_token_instance = client.access_token! 'none'
|
26
|
+
|
27
|
+
user = ForestLiana::AuthorizationGetter.authenticate(
|
28
|
+
rendering_id,
|
29
|
+
true,
|
30
|
+
{ :forest_token => access_token_instance.instance_variable_get(:@access_token) },
|
31
|
+
nil,
|
32
|
+
)
|
33
|
+
|
34
|
+
return ForestLiana::Token.create_token(user, rendering_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def parse_state(state)
|
39
|
+
unless state
|
40
|
+
raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_MISSING]
|
41
|
+
end
|
42
|
+
|
43
|
+
rendering_id = nil
|
44
|
+
|
45
|
+
begin
|
46
|
+
parsed_state = JSON.parse(state.gsub("'",'"').gsub('=>',':'))
|
47
|
+
rendering_id = parsed_state["renderingId"].to_s
|
48
|
+
rescue
|
49
|
+
raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_FORMAT]
|
50
|
+
end
|
51
|
+
|
52
|
+
if rendering_id.nil?
|
53
|
+
raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_RENDERING_ID]
|
54
|
+
end
|
55
|
+
|
56
|
+
return rendering_id
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|