Skip to content

Commit d58a2e0

Browse files
authored
refactor(auth): remove old session and 2fa logic (#ccukc7) (#418)
1 parent 0c7c049 commit d58a2e0

File tree

16 files changed

+50
-396
lines changed

16 files changed

+50
-396
lines changed

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ 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'
3735
gem 'openid_connect', '1.2.0'

Gemfile.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
PATH
22
remote: .
33
specs:
4-
forest_liana (6.0.0-beta.4)
4+
forest_liana (6.0.0.pre.beta.4)
55
arel-helpers
6-
base32
76
bcrypt
87
groupdate (= 2.5.2)
98
httparty
@@ -15,7 +14,6 @@ PATH
1514
openid_connect
1615
rack-cors
1716
rails (>= 4.0)
18-
rotp
1917
useragent
2018

2119
GEM
@@ -80,7 +78,6 @@ GEM
8078
arel-helpers (2.11.0)
8179
activerecord (>= 3.1.0, < 7)
8280
attr_required (1.0.1)
83-
base32 (0.3.4)
8481
bcrypt (3.1.16)
8582
bindata (2.4.8)
8683
builder (3.2.4)
@@ -177,7 +174,6 @@ GEM
177174
rake (>= 0.8.7)
178175
thor (>= 0.20.3, < 2.0)
179176
rake (13.0.1)
180-
rotp (6.2.0)
181177
rspec-core (3.8.2)
182178
rspec-support (~> 3.8.0)
183179
rspec-expectations (3.8.6)
@@ -237,7 +233,6 @@ PLATFORMS
237233

238234
DEPENDENCIES
239235
arel-helpers (= 2.11.0)
240-
base32 (= 0.3.4)
241236
bcrypt
242237
byebug
243238
forest_liana!
@@ -252,7 +247,6 @@ DEPENDENCIES
252247
rack-cors
253248
rails (= 6.0.3.4)
254249
rake
255-
rotp (= 6.2.0)
256250
rspec-rails (= 3.8.2)
257251
simplecov
258252
sqlite3 (~> 1.4)

app/controllers/forest_liana/authentication_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def authentication_callback
8686
render json: response_body, status: 200
8787

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

app/controllers/forest_liana/sessions_controller.rb

Lines changed: 0 additions & 95 deletions
This file was deleted.

app/serializers/forest_liana/session_serializer.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/services/forest_liana/authentication.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def verify_code_and_generate_token(redirect_url, params)
2626

2727
user = ForestLiana::AuthorizationGetter.authenticate(
2828
rendering_id,
29-
true,
3029
{ :forest_token => access_token_instance.instance_variable_get(:@access_token) },
31-
nil,
3230
)
3331

3432
return ForestLiana::Token.create_token(user, rendering_id)
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
module ForestLiana
22
class AuthorizationGetter
3-
def self.authenticate(rendering_id, use_google_authentication, auth_data, two_factor_registration)
3+
def self.authenticate(rendering_id, auth_data)
44
begin
55
route = "/liana/v2/renderings/#{rendering_id.to_s}/authorization"
6-
7-
if !use_google_authentication.nil?
8-
headers = { 'forest-token' => auth_data[:forest_token] }
9-
elsif !auth_data[:email].nil?
10-
headers = { 'email' => auth_data[:email], 'password' => auth_data[:password] }
11-
end
12-
13-
query_parameters = {}
14-
15-
unless two_factor_registration.nil?
16-
query_parameters['two-factor-registration'] = true
17-
end
6+
headers = { 'forest-token' => auth_data[:forest_token] }
187

198
response = ForestLiana::ForestApiRequester
20-
.get(route, query: query_parameters, headers: headers)
9+
.get(route, query: {}, headers: headers)
2110

2211
if response.code.to_i == 200
2312
body = JSON.parse(response.body, :symbolize_names => false)
2413
user = body['data']['attributes']
2514
user['id'] = body['data']['id']
2615
user
2716
else
28-
unless use_google_authentication.nil?
29-
raise "Cannot authorize the user using this google account. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
30-
else
31-
raise "Cannot authorize the user using this email/password. Forest API returned an #{Errors::HTTPErrorHelper.format(response)}"
32-
end
17+
raise generate_authentication_error response
3318
end
34-
rescue
35-
raise ForestLiana::Errors::HTTP401Error
3619
end
3720
end
21+
22+
private
23+
def self.generate_authentication_error(error)
24+
case error[:message]
25+
when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_AND_RENDERINGID_INCONSISTENT]
26+
return ForestLiana::Errors::InconsistentSecretAndRenderingError.new()
27+
when ForestLiana::MESSAGES[:SERVER_TRANSACTION][:SECRET_NOT_FOUND]
28+
return ForestLiana::Errors::SecretNotFoundError.new()
29+
else
30+
end
31+
32+
serverError = error[:jse_cause][:response][:body][:errors][0] || nil
33+
34+
if !serverError.nil? && serverError[:name] == ForestLiana::MESSAGES[:SERVER_TRANSACTION][:names][:TWO_FACTOR_AUTHENTICATION_REQUIRED]
35+
return ForestLiana::Errors::TwoFactorAuthenticationRequiredError.new()
36+
end
37+
38+
return StandardError.new(error)
39+
end
3840
end
3941
end

app/services/forest_liana/login_handler.rb

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)