Skip to content

Commit 3be27e0

Browse files
authored
chore(force-release): release forest-rails 6
2 parents 6662bbb + b18f047 commit 3be27e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+669
-395
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ build/
3333
# for a library or gem, you might want to ignore these files since the code is
3434
# intended to run in multiple environments; otherwise, check them in:
3535
# Gemfile.lock
36-
.ruby-version
3736
# .ruby-gemset
3837

3938
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
@@ -43,3 +42,7 @@ node_modules/
4342

4443
# IDE
4544
/.idea/
45+
46+
# rbenv
47+
.ruby-version
48+

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,68 @@
2626

2727
* **smart-action-hook:** value injected to an enum field of type is now correctly handled ([#414](https://github.com/ForestAdmin/forest-rails/issues/414)) ([ef90105](https://github.com/ForestAdmin/forest-rails/commit/ef90105659f57c4c8531b0c4d576f345bc976b33))
2828

29+
# [6.0.0-beta.4](https://github.com/ForestAdmin/forest-rails/compare/v6.0.0-beta.3...v6.0.0-beta.4) (2021-01-15)
30+
31+
32+
### Bug Fixes
33+
34+
* **auth:** support multi-instances and remove auth's redirection ([#407](https://github.com/ForestAdmin/forest-rails/issues/407)) ([8fcf9d4](https://github.com/ForestAdmin/forest-rails/commit/8fcf9d4ba0f41b8c98451a3d15d31c73ab4fd162))
35+
36+
# [6.0.0-beta.3](https://github.com/ForestAdmin/forest-rails/compare/v6.0.0-beta.2...v6.0.0-beta.3) (2020-12-14)
37+
38+
39+
### Bug Fixes
40+
41+
* fix test after enums ([#398](https://github.com/ForestAdmin/forest-rails/issues/398)) ([7b37350](https://github.com/ForestAdmin/forest-rails/commit/7b37350fc2b6244c3180cb953c2954d5b6927739))
42+
* **smart-actions:** reset value when not present in enums in hook response ([#397](https://github.com/ForestAdmin/forest-rails/issues/397)) ([a1ddac1](https://github.com/ForestAdmin/forest-rails/commit/a1ddac1c0d474e11b43e0f489dcc5ea70cd940b8))
43+
* **smart-actions:** transform legacy widgets in hooks ([#395](https://github.com/ForestAdmin/forest-rails/issues/395)) ([0183d08](https://github.com/ForestAdmin/forest-rails/commit/0183d0883c85fa2569cba70d268747536770a612))
44+
* **smart-actions:** use changedField instead of comparing values to trigger the correct change hook ([#396](https://github.com/ForestAdmin/forest-rails/issues/396)) ([d65c065](https://github.com/ForestAdmin/forest-rails/commit/d65c065319f9ab83d909214a2a71923467a78a0d))
45+
46+
47+
### Features
48+
49+
* **role:** add support for new roles ACL permissions ([#391](https://github.com/ForestAdmin/forest-rails/issues/391)) ([ae3539e](https://github.com/ForestAdmin/forest-rails/commit/ae3539e59c49b525078639a6d316ae2b5598ed75))
50+
* handle hooks ([#382](https://github.com/ForestAdmin/forest-rails/issues/382)) ([8dd0e35](https://github.com/ForestAdmin/forest-rails/commit/8dd0e356be27b33379b2aaa0376deb3a76123300))
51+
2952
# [5.4.0](https://github.com/ForestAdmin/forest-rails/compare/v5.3.3...v5.4.0) (2020-12-10)
3053

3154

3255
### Features
3356

3457
* **role:** add support for new roles ACL permissions ([#391](https://github.com/ForestAdmin/forest-rails/issues/391)) ([ae3539e](https://github.com/ForestAdmin/forest-rails/commit/ae3539e59c49b525078639a6d316ae2b5598ed75))
3558

59+
# [6.0.0-beta.2](https://github.com/ForestAdmin/forest-rails/compare/v6.0.0-beta.1...v6.0.0-beta.2) (2020-12-09)
60+
61+
62+
### Bug Fixes
63+
64+
* **gemfile:** gemfile.lock forest_liana version mismatch ([#401](https://github.com/ForestAdmin/forest-rails/issues/401)) ([60ceaf1](https://github.com/ForestAdmin/forest-rails/commit/60ceaf195371c56ee327cffbd40e8b85bf42ea3a))
65+
66+
67+
### Features
68+
69+
* **auth:** authenticate using oidc ([#400](https://github.com/ForestAdmin/forest-rails/issues/400)) ([4898b73](https://github.com/ForestAdmin/forest-rails/commit/4898b73bc70bf3a4828d7cdf63cd642add10b643))
70+
71+
72+
### BREAKING CHANGES
73+
74+
* **auth:** Introduces a new authentication system.
75+
- The application_url property is required to initialize ForestLiana,
76+
- CORS rules must be adapted (to allow null origins).
77+
78+
# [6.0.0-beta.1](https://github.com/ForestAdmin/forest-rails/compare/v5.2.3...v6.0.0-beta.1) (2020-12-09)
79+
80+
81+
### Features
82+
83+
* **auth:** authenticate using oidc ([#383](https://github.com/ForestAdmin/forest-rails/issues/383)) ([b535ab4](https://github.com/ForestAdmin/forest-rails/commit/b535ab4e7e7e371c93d01bdb41c6006bd9acc7cd))
84+
85+
86+
### BREAKING CHANGES
87+
88+
* **auth:** New authentication system.
89+
The application_url must be set in the ForestLiana initializer, adding a regex CORS rule for null origin is required.
90+
3691
## [5.3.3](https://github.com/ForestAdmin/forest-rails/compare/v5.3.2...v5.3.3) (2020-12-08)
3792

3893

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ gem 'groupdate', '2.5.2'
3030
gem 'useragent'
3131
gem 'jwt'
3232
gem 'bcrypt'
33-
gem 'base32', '0.3.4'
34-
gem 'rotp', '6.2.0'
3533
gem 'httparty', '0.18.1'
3634
gem 'ipaddress', '0.8.3'
35+
gem 'openid_connect', '1.2.0'
36+
gem 'json'
37+
gem 'json-jwt', '1.12.0'

Gemfile.lock

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
PATH
22
remote: .
33
specs:
4-
forest_liana (5.4.4)
4+
forest_liana (6.0.0.pre.beta.4)
55
arel-helpers
6-
base32
76
bcrypt
87
groupdate (= 2.5.2)
98
httparty
109
ipaddress
10+
json
11+
json-jwt
1112
jsonapi-serializers (>= 0.14.0)
1213
jwt
14+
openid_connect
1315
rack-cors
1416
rails (>= 4.0)
15-
rotp
1617
useragent
1718

1819
GEM
@@ -73,10 +74,12 @@ GEM
7374
minitest (~> 5.1)
7475
tzinfo (~> 1.1)
7576
zeitwerk (~> 2.2, >= 2.2.2)
77+
aes_key_wrap (1.1.0)
7678
arel-helpers (2.11.0)
7779
activerecord (>= 3.1.0, < 7)
78-
base32 (0.3.4)
80+
attr_required (1.0.1)
7981
bcrypt (3.1.16)
82+
bindata (2.4.8)
8083
builder (3.2.4)
8184
byebug (11.1.3)
8285
concurrent-ruby (1.1.7)
@@ -91,10 +94,15 @@ GEM
9194
httparty (0.18.1)
9295
mime-types (~> 3.0)
9396
multi_xml (>= 0.5.2)
97+
httpclient (2.8.3)
9498
i18n (1.8.5)
9599
concurrent-ruby (~> 1.0)
96100
ipaddress (0.8.3)
97101
json (2.5.1)
102+
json-jwt (1.12.0)
103+
activesupport (>= 4.2)
104+
aes_key_wrap
105+
bindata
98106
jsonapi-serializers (1.0.1)
99107
activesupport
100108
jwt (2.2.2)
@@ -117,9 +125,26 @@ GEM
117125
nio4r (2.5.4)
118126
nokogiri (1.10.10)
119127
mini_portile2 (~> 2.4.0)
128+
openid_connect (1.2.0)
129+
activemodel
130+
attr_required (>= 1.0.0)
131+
json-jwt (>= 1.5.0)
132+
rack-oauth2 (>= 1.6.1)
133+
swd (>= 1.0.0)
134+
tzinfo
135+
validate_email
136+
validate_url
137+
webfinger (>= 1.0.1)
138+
public_suffix (4.0.6)
120139
rack (2.2.3)
121140
rack-cors (1.1.1)
122141
rack (>= 2.0.0)
142+
rack-oauth2 (1.16.0)
143+
activesupport
144+
attr_required
145+
httpclient
146+
json-jwt (>= 1.11.0)
147+
rack (>= 2.1.0)
123148
rack-test (1.1.0)
124149
rack (>= 1.0, < 3)
125150
rails (6.0.3.4)
@@ -149,7 +174,6 @@ GEM
149174
rake (>= 0.8.7)
150175
thor (>= 0.20.3, < 2.0)
151176
rake (13.0.1)
152-
rotp (6.2.0)
153177
rspec-core (3.8.2)
154178
rspec-support (~> 3.8.0)
155179
rspec-expectations (3.8.6)
@@ -180,11 +204,24 @@ GEM
180204
activesupport (>= 4.0)
181205
sprockets (>= 3.0.0)
182206
sqlite3 (1.4.2)
207+
swd (1.2.0)
208+
activesupport (>= 3)
209+
attr_required (>= 0.0.5)
210+
httpclient (>= 2.4)
183211
thor (1.0.1)
184212
thread_safe (0.3.6)
185213
tzinfo (1.2.8)
186214
thread_safe (~> 0.1)
187215
useragent (0.16.10)
216+
validate_email (0.1.6)
217+
activemodel (>= 3.0)
218+
mail (>= 2.2.5)
219+
validate_url (1.0.13)
220+
activemodel (>= 3.0.0)
221+
public_suffix
222+
webfinger (1.1.0)
223+
activesupport
224+
httpclient (>= 2.4)
188225
websocket-driver (0.7.3)
189226
websocket-extensions (>= 0.1.0)
190227
websocket-extensions (0.1.5)
@@ -195,19 +232,20 @@ PLATFORMS
195232

196233
DEPENDENCIES
197234
arel-helpers (= 2.11.0)
198-
base32 (= 0.3.4)
199235
bcrypt
200236
byebug
201237
forest_liana!
202238
groupdate (= 2.5.2)
203239
httparty (= 0.18.1)
204240
ipaddress (= 0.8.3)
241+
json
242+
json-jwt (= 1.12.0)
205243
jsonapi-serializers (= 1.0.1)
206244
jwt
245+
openid_connect (= 1.2.0)
207246
rack-cors
208247
rails (= 6.0.3.4)
209248
rake
210-
rotp (= 6.2.0)
211249
rspec-rails (= 3.8.2)
212250
simplecov (~> 0.17.0)
213251
sqlite3 (~> 1.4)

app/controllers/forest_liana/application_controller.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
module ForestLiana
55
class ApplicationController < ForestLiana::BaseController
6-
REGEX_COOKIE_SESSION_TOKEN = /forest_session_token=([^;]*)/;
7-
86
def self.papertrail?
97
Object.const_get('PaperTrail::Version').is_a?(Class) rescue false
108
end
@@ -64,7 +62,7 @@ def authenticate_user_from_jwt
6462
token = request.headers['Authorization'].split.second
6563
# NOTICE: Necessary for downloads authentication.
6664
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'])
6866
token = match[1] if match && match[1]
6967
end
7068

@@ -97,10 +95,6 @@ def get_smart_action_context
9795
end
9896
end
9997

100-
def route_not_found
101-
head :not_found
102-
end
103-
10498
def internal_server_error
10599
head :internal_server_error
106100
end
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
render json: { authorizationUrl: result['authorization_url']}, status: 200
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: error.error_code || 500, detail: error.message }] },
90+
status: error.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

app/controllers/forest_liana/base_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ class BaseController < ::ActionController::Base
44
wrap_parameters false
55
before_action :reject_unauthorized_ip
66

7+
def route_not_found
8+
head :not_found
9+
end
10+
711
private
812

913
def reject_unauthorized_ip

0 commit comments

Comments
 (0)